function largestOfFour(arr) {
// You can do this!
var results = arr.map(function(num) {
var largestNumber = 0;
for (let i = 0; i < num.length; i++) { // <-- here you were missing comparison
if (num[i] > largestNumber) { // <-- here you were using arr instead of num and comparing to what?
largestNumber = num[i]; // <-- same here
}
}
return largestNumber;
});
return results;
}
Thank you very much.
I did the correct the loop and the name of variables.
I am trying to solve without consulting the internet, so I forget some part of code.
i am training for interview.
Thanks, I don’t know what happen I forgot a important part of loop, I saw the error infinite loop, but I didn’t saw it was missing variable > variable.length.
I saw an answer with two loops, but I wanna to reduce the code. I always make confusion with arr[i] and arr[i][j], I don’t know why.