Return Largest num in arrays code not passing

I cannot see why my last test isn’t passing. I’m getting no errors and the return is correct. Any help appreciated!

function largestOfFour(arr) {
  let newArr = [0, 0, 0, 0];
  for (let i=0; i < arr.length; i++) {
    for (let j=0; j < arr[i].length; j++){
     if(arr[i][j] > newArr[i]) {         
          newArr[i] = arr[i][j];
        } 
    }
  }
  return newArr;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);

This is the test in question:

largestOfFour([[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]) should return [25, 48, 21, -3] .

because, your solution is being tested against negative numbers, and 0 is greater than any negative number, to make your solution work you’d have to initialize with something like this
let newArr = [-Infinity, -Infinity,-Infinity,-Infinity];

1 Like

gotcha thank you! This was my problem.