Tell us what’s happening:
i can’t complete the challenge because my code fail to return -3 on the last test
largestOfFour([[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]])
should return [25, 48, 21, -3]
.
Your code so far
function largestOfFour(arr) {
// You can do this!
var largest = [];
for(var i = 0; i < arr.length; i++){
var v = 0;
for(var j = 0; j < arr[i].length; j++){
if(arr[i][j] > v){
v = arr[i][j];
} else {
Math.max.apply(...arr[i][j]);
}
}
largest.push(v);
}
return largest;
}
console.log(largestOfFour([[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/return-largest-numbers-in-arrays