Hello, I’m trying to resolve the Return Largest Numbers in Arrays algorithm challenge with this:
/* jshint esversion: 6 */
function largestOfFour(arr) {
var max=[];
for(var i=0; i<arr.length; i++){
for(var j=0; j<arr[i].length; j++){
max.push(Math.max(...arr[j]));
}
}
return max;
}
largestOfFour([[13, 27, 18, 26], [4, 5, 1, 3], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
output:
And it, in fact, returns the largest number for each array but four times, I’m guessing because of the length of the outermost array. So I would like to know why is this happening and what I’m doing wrong, thank you.