Tell us what’s happening:
Hey, ive got a problem with this exercise. Exactly with the fact that my code add the biggest values to the array largestNumbers in the loop, BUT when i want to actually extract that variable largestNumbers with its array out of the loop then, well, i cant… I cant understand why, can anybody explain?
Your code so far
function largestOfFour(arr) {
// You can do this!
var largestNumbers = [];
var largest = -100000;
for (var i = 0; i <= arr.length; i++) {
for (var j = 0; j < arr[i].length; j++) {
if (arr[i][j] > largest) {
largest = arr[i][j];
}
}
largestNumbers.push(largest);
largest = -100000;
console.log(largestNumbers); // here it shows the array correctly [25,48,21,-3]
}
console.log(largestNumbers); // here i cant acces it, help pls
return largestNumbers;
}
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/70.0.3538.102 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/return-largest-numbers-in-arrays/