Ad
Algorithms
Logic
Data Structures

You are working to an accounting company and your boss ask to make a program to get the most worked years.

Him already have the data in the database and will response with a matrix data.

For example: [[2001,2005],[1920,1960],[2001,1999],...] what you
will receive from the database.

The program only should return only an integer value corresponding to the most worked year.

const mostWorkedYears = (matrix) =>
  matrix
    .map((item) => item[0])
    .reduce(
      (accum, curr, index, array) =>
        curr === array[index + 1] ? accum + curr : curr,
      0
    );