Tell us what’s happening: I understand how to solve this problem if we are just looping through one array but I dont really understand how to do when we add the other 3 sub arrays in.
Right now my code returns: [4, 5, 5, 5,]
Your code so far
function largestOfFour(arr) {
// You can do this!
var result = [];
var largeNum = 0;
for (var i = 0; i < arr.length; i++) {
for (var j = 0; j < 4; j++) {
if (arr[i][j] > largeNum) {
largeNum = arr[i][j];
}
result.push(largeNum);
}
return result;
}
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36.
Link to the challenge:
https://www.freecodecamp.org/challenges/return-largest-numbers-in-arrays