Return Largest Numbers in Arrays, last test fails

Return Largest Numbers in Arrays, last test fails
0.0 0

#1

So my code passes the first 3 tests, but fails
largestOfFour([[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]) should return [25, 48, 21, -3].
What am I missing?

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

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

#2

That is because off the above line. You always start with bigNum equal to zero. Based on your if statement you will always be comparing arr[i][j] to a number greater or equal to zero, so any negative numbers in arr[i] will result in your if statement (seen below) evaluating to false and not assigning arr[i][j] to bigNum.

if (arr[i][j] > bigNum) {

In the test case where the last element of the nested array is all negative numbers, your code will return 0 for the last element of finalArray [ 25, 48, 21, 0 ].