Tell us what’s happening:
Describe your issue in detail here.
Hello everyone. I have gone to the “hint” area and see that I nuked the ever living crap out of this. But I see how there is an easy way in the hints - but would someone PLEASE explain to me why this is giving me the console:
“Starting with highest number: -72
Looking at the next NEGATIVE number: -3
The current highest number is: -72
If -3 is < -72
Is -3 > ‘-72’?
NOPE!
-3 is NOT > ‘-72’
The highest number is still -72”
I do NOT get why it thinks that -3 is not larger than -72.
Please help. Thank you all.
**Your code so far**
function largestOfFour(arr) {
let num = [];
for (let i = 0; i < arr.length; i++){
console.log("-----------------------")
console.log("Round # "+i);
num.push([0]);
for (let k = 0; k < arr[i].length; k++) {
console.log("----------")
console.log("Starting with highest number: " + num[i]);
// IF IT'S A NEGATIVE NUMBER
if (Math.sign(arr[i][k]) === -1)
{
console.log("Looking at the next NEGATIVE number: " + arr[i][k]);
console.log("The current highest number is: "+num[i]);
console.log("If " + arr[i][k] + " is < " + num[i])
if (arr[i][k] < num[i]) {
console.log("Is " + arr[i][k] + " < "+ + num[i])
num[i]=arr[i][k];
console.log("It is! (Negative)")
console.log("Highest number is now "+ num[i])
} else
{
console.log("Is " + arr[i][k] + " > "+ "'" + num[i]+"'?")
console.log("NOPE!");
console.log(arr[i][k] + " is NOT > "+ "'" + num[i]+"'")
console.log("The highest number is still "+num[i]);
}
}
//IF it's a POSITIVE NUMBER
else if (Math.sign(arr[i][k]) === 1)
{
console.log("Looking at the next POSITIVE number: " + arr[i][k]);
if(arr[i][k] > num[i])
{
console.log("Is " + arr[i][k] + " > " + num[i]+"?")
num[i]=arr[i][k];
console.log("It is!")
console.log("Highest number is now "+ "'" + num[i]+"'")
} else
{
console.log("Is " + arr[i][k] + " > "+ "'" + num[i]+"'?")
console.log("NOPE!");
console.log(arr[i][k] + " is NOT > "+ "'" + num[i]+"'")
console.log("The highest number is still "+num[i]);
}
}
}
console.log("The Largest numbers so far are: " + num);
}
console.log(num);
return num;
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [-72, -3, -17, -10]]);
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36
Challenge: Return Largest Numbers in Arrays
Link to the challenge: