Return Largest Numbers in Arrays with dual for loops

Tell us what’s happening:

Your code so far

function largestOfFour(arr) {
  // You can do this!
  max = 0;
      if(arr[i][j] > max)
         max = arr[i][j];
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/60.0.3112.78 Chrome/60.0.3112.78 Safari/537.36.

Link to the challenge:

You have a few different problems. I will help you with 2 of them and I will let you figure out the others on your own.

#1) Your function does not return anything. You need to use the return statement before the end of the function.

#2) You if statement does not ever get executed, because of a problem in your nested for loop:


arr[i] a specific inner array. What you want is arr[i].length, so the nested for loop will terminate after each inner array is traversed.

Remember, the challenge is suppose to return an array of the largest number of each inner array, so it will look something like:

[ 5, 27, 39, 1001 ]