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
);
const Test = require("@codewars/test-compat");
const matrixYearsInput1 = [
[1960, 2005],
[1945, 2008],
[1938, 1999],
[1960, 2008],
[1999, 2005],
[1945, 1980],
[1960, 2001],
]
describe("Solution", function() {
it("Should return the most worked year: 1960", () => {
Test.assertEquals(mostWorkedYears(matrixYearsInput1), 1960);
});
});