function largestOfFour(arr) {
let newArr = [];
let max = 0;
for(let i = 0; i<arr.length;i++){
for(let j = 0; j<arr[i].length; j++){
if(arr[i][j]>max){
max = arr[i][j];
console.log(max);
newArr.push(max);
}
}
}
return newArr;
}
Hello I am writing a code to find the max value in an array of sub arrays and am required to add that max value to a new array. My code is above. The problem is my code is pushing every value greater than the max to the new array. When I just want the true max without using the Math.max function. I believe this is happening because I do not have a way of updating the max when a new max is found. Some guidance would be very helpful