Win a copy of Grokking Bitcoin this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Comparing 2 arrays to create a 3rd array of common items  RSS feed

 
Ranch Hand
Posts: 171
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to figure out the typescript logic to compare 2 arrays and create a 3rd array of all the common items

i.e.

ideally the third array would be something like:

Note that the is a duplicate of Nebraska, one for each person, and there is no listing for California as there no employee there.

Any suggestions on where I can find information on this?
 
John Morgan
Ranch Hand
Posts: 171
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Clearing up the code a little bit here is what I have :

I can display each of the arrays but I am looking at combining them.

Note that there is a duplicate of Nebraska, one for each person, and there is no listing for California as there no employee there and not listing for Bill Cody as there is no office in Wyoming.

I can figure it out in my head but not in code...
 
Ranch Hand
Posts: 368
2
Fedora IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you trying to just make the 3rd array in a method?  What are you gonna do with the 3rd atray?
 
Al Hobbs
Ranch Hand
Posts: 368
2
Fedora IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you do it only using the two arrays then you could just iterate through the employees array and look for a matching state in the office array.  If there's a match then you combine the data you want into another object and add it to the new array.

If theres only 5 offices the speed shouldnt be affected really.
 
John Morgan
Ranch Hand
Posts: 171
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am actually trying to run through 2 workbooks (one sheet in each), looking for duplicates in each via an employee number. I used the example up top to keep it simple...

The idea is I get the two workbooks in each month, I do a search for the duplicate employee numbers, create a copy of the first workbook and then copy some of columns from the second into the copy workbook. Removing any lines that do not have anything in common with the other. This is a time consuming task the way it is done right now and I would prefer to just create a program to do just that but I am worried I may have broken off more than I can chew.
 
Al Hobbs
Ranch Hand
Posts: 368
2
Fedora IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By workbook are you talking about excel or what?   Also  how is it being now thats so time consuming?
 
John Morgan
Ranch Hand
Posts: 171
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it is 2 excel workbooks that are sent to me, each contain approximately 600 lines that I have to go through manually and match up.
 
Al Hobbs
Ranch Hand
Posts: 368
2
Fedora IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh no. Oh nooo.   I think its funny that people worry about ai takeover l because i know there are tons of people in offices around the world that manually do stuff that a 30 yr old computer can do in a few milliseconds.

anyway  is there a reason you want to use typescript instead of java ?

The easiest way to do it is to convert the excel to csv so you can just read it without using an excel library.

Then you could put the excel sheets in a db if you are going to use the same one over and over again.

Or if you dont need to use it more than once then you can put one of them into a big map/dictionary and then iterate through one and check if theres a match in the map.
 
John Morgan
Ranch Hand
Posts: 171
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both are different each month... basically a correlation of data from multiple sources that needs to be compiled, combined, refined and distributed to other people. I am only using TypeScript for this as it is a pretty simple task (or so I thought) and I figured it would be a great learning project. Turns out it is a lot more complicated than i originally thought (I know it can be done in POJ but that would not help me learn TypeScript).
 
Al Hobbs
Ranch Hand
Posts: 368
2
Fedora IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well if you arent making a web app then you would need a way to run the javascript.  Correct me if im wrong but it seems like it would be way easier to just make a java app.    

You could also automate the sending of the new excel file too.

 
John Morgan
Ranch Hand
Posts: 171
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is exactly what I am going to have to do. I was hoping that I could take a project like this and use it to learn Angular but in this case it is just not feasible.  Thanks for all your replies and help.

Al Hobbs wrote:Well if you arent making a web app then you would need a way to run the javascript.  Correct me if im wrong but it seems like it would be way easier to just make a java app.    

You could also automate the sending of the new excel file too.

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!