Tell us what’s happening:
Hi everyone,
I was wondering how I can handle negative numbers with unknown value in the arrays. Do I add an insanely high amount of zeros to my maxNum = -100?
Or what do I need to do?
I thought about using Math.min( ) as value for maxNum, but this will log infinity for every number in the final array.
What am I missing?
Looking forward to your help!
Your code so far
function largestOfFour(arr) {
let arrMax = [];
for (let i = 0; i < arr.length; i++){
let maxNum = -100;
for(let j = 0; j < arr[i].length; j++){
if(arr[i][j] > maxNum){
maxNum = arr[i][j];
}
}
arrMax.push(maxNum);
console.log(arrMax)
}
return arrMax;
}
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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Challenge Information:
Basic Algorithm Scripting - Return Largest Numbers in Arrays