Tell us what’s happening:
So I’m passing 3 out of 4 tests and I’m unsure how to pass the 4th one. Cause the 4th one has negative numbers in its output and I don’t know what I should change? I mean I’ve read on some posts that this line:
var newArr = [0,0,0,0];
could be the problem and I think it might be as well? I just don’t know how to adapt it to pass that last damn test? All help is welcome!
Thanks in advance!
Regards
Ma3_str0
Your code so far
function largestOfFour(arr) {
var newArr = [0,0,0,0];
for(let i = 0;i < arr.length;i++){
for(let j = 0;j < arr[i].length;j++){
if(arr[i][j] > newArr[i]){
newArr[i] = arr[i][j];
}
}
}
return newArr;
}
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; rv:76.0) Gecko/20100101 Firefox/76.0
.
Challenge: Return Largest Numbers in Arrays
Link to the challenge: