# What's wrong | Return Largest Numbers in Arrays

What's wrong | Return Largest Numbers in Arrays
0

#1

Tell us what’s happening:
I want to understand what the flaw in my logic here is. I included comments to explain what I want to do.

Your code so far

``````
function largestOfFour(arr) {
let newArr = [] //creates a new array to push new values into
for (let i = 0; i < arr[i].length; i++){
//'i' is set to  and compared to the length of my subarray, which is 4. as long as it is less than the set length the following runs:
for (let j=0; j < arr[i][j]; j++){
//j is a comparison value that starts at 0. It's compared with the initial value of the currently indexed array. as long as j is less than this value the following runs:
if (j < arr[i][j]){
j = arr[i][j] // if j is less than value shown, let j equal that value
}else{
newArr.push(j);
}
//else if j is equal to or greater than the value shown push j into the newArr array and go to the next subarray)
}
}
// You can do this!
return newArr;
}

console.log(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/69.0.3497.100 Safari/537.36`.

#2

Right here. This is illegal to do this. You probably meant to do

`let i=0; i<arr.length; i++`
and inside
`let j=0; j<arr[i].length; j++`