Tell us what’s happening:
Hi !
I’m stuck with my code, I think I found the mistake but i can’t solve it .
As long as the numbers in the following array are bigger the code works, but if an array contains smaller numbers than the previous array the code seems to ignore it.
exemple :
[[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]
will return [25, 48, 48, 48]
Your code so far
function largestOfFour(arr) {
let newArr = [];
let biggerNum = 0;
for (let i = 0; i < arr.length; i++){ // on parcours le premier tableau
for (let j = 0; j < arr[i].length; j++){ // on parcours le second tableau
if(arr[i][j] >= biggerNum){
biggerNum = arr[i][j];
}
}
newArr.push(biggerNum)
console.log(newArr);
}
return newArr
}
largestOfFour([[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:79.0) Gecko/20100101 Firefox/79.0
.
Challenge: Return Largest Numbers in Arrays
Link to the challenge: