Easy one.
console.log([10, 2, 5].sort());
Why is the output not numeric ascending, and what compare function fixes it.
Sora ![]()
Easy one.
console.log([10, 2, 5].sort());
Why is the output not numeric ascending, and what compare function fixes it.
Sora ![]()
sort() compares as strings by default, so "10" comes before "2" lexicographically.
Sarah
:: Copyright KIRUPA 2024 //--