function largestOfFour(arr) {
var larnumArr = []
var larnum = 0;
for (var i = 0; i < arr.length; i++) {
if (arr[i][i] > larnum) {
larnum = arr[i][i];
}
larnumArr.push(larnum)
}
return larnumArr;
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
console.log(largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]))
Here’s the code I typed. When logging console.log(largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]))
, I have the following output [ 4, 27, 37, 37 ]
.
The 37 shows up twice at the end of my array, but it should outputs 1001 to get it right.
While im near the solution, I can’t see where my mistake is in the code?
Does anybody have a clue ?