Return Largest Numbers in Arrays-Negative?

Tell us what’s happening:

It’s not passing the last test.

Your code so far


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

 
 

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 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36.

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

Hi, you can make use of -Infinity in this case (replace with your zeroes). More info

Thanks for the reply. Sorry I’m new to this. Would it be like this
var largest = -Infinity

Hi,

You have to replace all the zeros with the -Infinity value in the largest array.

var largest = [-Infinity, -Infinity, -Infinity, -Infinity];
Ahh thanks!!