I can't understand please clear my doubt

Tell us what’s happening:

arr[i] is not defined it showing that error can you explain why ??

Your code so far


function largestOfFour(arr) {
let largestArray=[];
let maximum=0;
for(let i=0;i<arr.length;i++){
  for(let j=0;j<arr[i].length;i++){
    if(arr[i][j]>maximum){
      maximum=arr[i][j];
      largestArray=arr[i];
    }
  }
}
return largestArray;
}

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:80.0) Gecko/20100101 Firefox/80.0.

Challenge: Return Largest Numbers in Arrays

Link to the challenge:

you are increasing i inside the inner loop, instead of j
that’s why you get that error

1 Like