Code isn't working as expected

Tell us what’s happening:

  **Your code so far**

function largestOfFour(arr) {
let max = 0;
let arrFinal = [];
for(let i=0;i<arr.length;i++){
  max = Math.max(...arr[i]);
  arrFinal.push[max];
  max = 0;
}
return arrFinal;
}

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

Challenge: Return Largest Numbers in Arrays

Link to the challenge:

Your syntax is incorrect. push is an array method. How do you call a method?

FYI - Once you figure out the above issue, you should know that the following lines are not needed:

let max = 0;

and

max = 0;

Why? You could just initialize max within the for loop using Math.max.

got it. Thank you @RandellDawson

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.