Skip to content
Advertisement

Line up two tables

I have two following arrays:

JavaScript

Now I want to take the common part of them, based on the date value, starting from the top and bottom, so the result should look like this:

JavaScript

I have started with something like this:

JavaScript

But it does not work, if there is a difference in the middle, how can I repair this?

Advertisement

Answer

  • Get all years from both arrays, make them unique to remove the doubles and sort them numeric.

  • Iterate through all years. If not both have the same year, just continue, else keep them both and add to the results.

JavaScript

The results look like

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement