Tell us what’s happening:
Even though the variables i and j has to be return 0,1,2,3
arr[i][j] outputs 0,1,2,3,4,5 and I couldn’t get why it is happening.
Your code so far
function largestOfFour(arr) {
let anArr=[];
for(let i=0; i<arr.length; i++){
for(let j=0; j<arr[i].length; j++){
if(arr[i][0]<arr[i][j]){
arr[i][0]=arr[i][j];
anArr.push(arr[i][j]);
}
}
}
return console.log(anArr);
}
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 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36
.
Challenge: Return Largest Numbers in Arrays
Link to the challenge: