Where am I messing up?

Tell us what’s happening:

Your code so far


function largestOfFour(arr) {
let maxNum = [];
for (let i = 0; i < arr.length; i++) {
  let tempMax = arr[i][0];
  for (let j = 0; j < arr[i].length; i++) {
    let currentValue = arr[i][j];
    if (currentValue >= tempMax) {
      tempMax = currentValue;
    };
  }
  maxNum.push(tempMax);
}
return maxNum;
}

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/83.0.4103.116 Safari/537.36 Edg/83.0.478.56.

Challenge: Return Largest Numbers in Arrays

Link to the challenge:

Hi @st_rutter
Your for loops are good just on your if condition your not comparing your array and your sub array. and then copy the high array into an empty array with the largest. and also you will need to create an empty array.

var largeArr = [0,0,0,0];
if(arr[arrayIndex][subArray] > largeArr[arrayIndex]) { 
          largeArr[arrayIndex] = arr[arrayIndex][subArray];
 }
1 Like

In your “j” loop you increment “i” rather than “j”. The rest is good.

1 Like

Yes that’s true i miss that one… push will be also a good way of doing it. rather than copy an array.