Hint
Default Array.sort() is lexicographic. Always pass (a,b) => a-b for numeric sorting.
const nums = [10, 9, 2, 1, 100];
console.log([...nums].sort().join(','));
console.log([...nums].sort((a, b) => a - b).join(','));1,10,100,2,9 1,2,9,10,100
Explanation: Default sort converts to strings: "10" < "2" because "1"<"2". With comparator (a-b): numeric sort works.
Key Insight: Default Array.sort() is lexicographic. Always pass (a,b) => a-b for numeric sorting.