Tell us what’s happening:
when I try to run this code ,the output that I am getting was [25, 48, 21, 0] instead of [25, 48, 21, -3]. Help me ,fix the code to get required output.
Your code so far
function largestOfFour(arr) {
let new_arr=[],max=0;
for(var i=0;i<arr.length;i++){
for(var j =0;j<arr[i].length;j++){
if(max<=arr[i][j]){
max = arr[i][j];
}
}
new_arr.push(max);
max=0;
}
console.log(new_arr);
return new_arr;
}
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 (X11; Ubuntu; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0
.
Challenge: Return Largest Numbers in Arrays
Link to the challenge: