Basic Algorithm Scripting - Return Largest Numbers in Arrays

Tell us what’s happening:
Code works fine, but the output in the challenges should be [27, 5, 39, 1001] and I get [ 5, 27, 39, 1001 ]. Why should the 27 and 5 be switched?

Your code so far

function largestOfFour(arr) {
  let num = [];
  let lnum = 0;
  for(let i = 0; i <= arr.length; i++){
    //console.log(arr[i]);
    for(let x = 0; x <= arr[i].length; x++){
      //console.log(arr[i][x]);
      if(arr[i][x] > lnum){
        lnum = arr[i][x];
      }
    }
    num.push(lnum);
    console.log(num);
  }
  return num;
}

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

Challenge: Basic Algorithm Scripting - Return Largest Numbers in Arrays

Link to the challenge:

It might be because in the 2nd test, the call is:

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

In your call, you have the subarrays in a different order:

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

Did not actually test your code though.

The tests disagree with you.

I also get :

TypeError: Cannot read properties of undefined (reading ‘length’)

You may want to review how to loop through an array, how the index works.