I want to find the max number among the first and second elements of each array inside the array of arrays separately:
function largestOfElements(mainArray) {
return mainArray.map(function(subArray) {
return subArray.reduce(function(previousLargestNumber, currentLargestNumber) {
return (currentLargestNumber > previousLargestNumber) ? currentLargestNumber : previousLargestNumber;
}, 0);
});
}
console.log(largestOfElements([
[],
[13, 47],
[38, 35],
[24, 34]
]));
.as-console-wrapper {
max-height: 100% !important;
top: 0;
}
the current way returns an array of the largest numbers in each array. How can I return the largest of the first elements and the largest of the second elements? the expected result will be:
[38, 47]