Return Largest Numbers in Arrays test not passing

Tell us what’s happening:

my code does return the right subarray but, still not passing the test…can somebody help?

Your code so far



function largestOfFour(arr) {
  // You can do this!
    let greatest=0;
    let greatArr=[];
    for(let i=0; i<arr.length; i++){
        
    for(let j=0; j<arr[i].length; j++){
        
    if(arr[i][j]>greatest){
        greatest=arr[i][j];
        greatArr=arr[i];
    }
    }
        
    }
    
    
  return greatArr;
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/return-largest-numbers-in-arrays

Hey @Zorba11,

should return
[5, 27, 39, 1001]
whereas your code returns
[1000, 1001, 857, 1]

See if you can solve now.
Does this help?

Thank you. That clarifies. I’ll try.