Return Largest Numbers in Arrays0

Tell us what’s happening:

help me out with this challenge. Thanks in advance.

Your code so far


function largestOfFour(arr) {
  // You can do this!
  var max = 0,i,j,res = [];
  for (i = 0; i < arr.length; i++) {
    for(j = 0; j < arr[i].length; j++) {
        if (arr[i][j] > max)
        {
          max = arr[i][j];
        }
    }
    return res[i] = max;
  }
  return res;
}

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 (X11; Ubuntu; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0.

Link to the challenge:

Learn about Math.max(); and Math.min();
Search each sub arrays to find the max number you might want to use reduce and ternary operator as well.

  1. You can’t use 0 as the baseline for the check, what if the largest number is negative? Try using the first element in each sub array for the check.

  2. You have two return statements. Remember the return statement will exit the function, remove the first return statement and just keep the assignment.