Return Largest Numbers in Arrays, Got the right answer but code no passing

Return Largest Numbers in Arrays, Got the right answer but code no passing
0

#1

Tell us what’s happening:
Hello I got the answer right but the code is not passing because the array is suppose to have an space between numbers and mine does not have the space, does anyone know how to add it? I know I have the solution in other topics here but I want to know why my code is not working

the result: [9,5,37,1000000]

Your code so far


function largestOfFour(arr) {
  // You can do this!

   for(var i = 0; i < arr.length; i++){
   
    for(var j = 3; j < arr[i].length; j++){

    result.push(Math.max.apply(null, arr[i]));
    }
  }
  //return the first 4 num
  return result;
}

largestOfFour([[4, 9, 1, 3], [13, 35, 18, 26], [32, 35, 97, 39], [1000000, 1001, 857, 1]]);

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36.

Link to the challenge:


#2

I do not see where you declared your result array, but I assume you declared it globally outside your function. Move the declaration inside your function before your for loops and see what you get.


#3

Yes that was the issue I had the var globally, thank you so much, but why is that? I cant see the logic