This code returns min, how is this possible?
if(prices[i] == 1000 && min == 53){
if(prices[i] < min){
return min;
}
return prices[i];
}
The values are strings. When you use == to compare them to numbers, the numbers are first (internally) converted to strings. However, the < compares the two strings as strings, and as such the string "1000" is in fact less than the string "53", because "1" comes before "5" in the character set.
Funny things happen when you compare strings and not numbers
console.log("strings", "1000" < "53")
console.log("numbers", 1000 < 53)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With