function largestOfFour(arr) {
//Empty array to store the values
let array = [];
let largest = 1;
//Loop through the array
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr[i].length; j++) {
//condition
if (arr[i][j] > largest) {
largest = arr[i][j];
}
}
array.push(largest);
}
return array;
}
console.log(largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]));
You are initializing largest as 1, but at-least one of the input arrays has all negative values. This will give you issues.
You are going to want to reset the value of largest after comparing a set of 4 values. The way you have it now, if your input is ([1, 2, 3, 4], [0,1,2,3]) your output will be [4,4].