I don’t seem to find out where it went wrong…I would much appreciate your comments
Desired Output: [27,5,39,1001]
Output Displayed: [ 27, 27, 39, 1001 ]
function largestOfFour(arr) {
let maxArray = [];
let splitted = [];
let max = 0;
for (let i = 0; i < arr.length; i++){
splitted = arr[i];
//console.log(splitted);
for(let j = 0 ; j < splitted.length; j++){
if (splitted[j] > max){
max = splitted[j];
//console.log(splitted);
}
}
//console.log(max);
maxArray.push(max);
//console.log(max);
}
//console.log(maxArray);
console.log(maxArray);
return maxArray;
}
largestOfFour([[13, 27, 18, 26], [4, 5, 1, 3], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
how else shall I initialize the value?
oh I see, although resetting the value of max to zero between subarrays worked for the non negative inputs, one of my tests still didn’t pass. what could be the reason behind this?
what if i don’t know what is going to be provided as an input? what value do I assign to max so that it can pass the test with array containing numbers like -9999999999999?