Stuck in Return Largest Number in Array

Stuck in Return Largest Number in Array
0.0 0

#1

Hello, I’m trying to resolve the Return Largest Numbers in Arrays algorithm challenge with this:

   /* jshint esversion: 6 */
    function largestOfFour(arr) {
      var max=[];
      for(var i=0; i<arr.length; i++){
        for(var j=0; j<arr[i].length; j++){
          
         max.push(Math.max(...arr[j]));
        }
        
      }
      return max;
      
    }

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

output:

And it, in fact, returns the largest number for each array but four times, I’m guessing because of the length of the outermost array. So I would like to know why is this happening and what I’m doing wrong, thank you.


#2

Got this answered in less than ten minutes in Stack Overflow. If anyone’s interested, I didn’t need the second loop, because Math.max takes the whole array. This solution, however, is not accepted by the editor for some reason.