Return Largest Numbers in out

Tell us what’s happening:
Hello, i’ve spent hours on this challenge and ive passed all tests except the last one, although my test did run perfectly on printing all largest numbers in each array. Anyone see what i’m missing? thanks.

Your code so far

function largestOfFour(arr) {
  var newArray = [];
  for (var i=0; i < arr.length; i++){
    var largestNum = 0;
    for(var j=0; j < arr.length; j++){
      if(largestNum < arr[i][j]){
         largestNum = arr[i][j];
  return newArray;

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/67.0.3396.87 Safari/537.36.

Link to the challenge:

Your logic is off a bit. By setting largestNum to zero before the inner for loop starts, your code fails if any of the values in a subarray are less than zero.

1 Like