Report #103674
[gotcha] Array.sort\(\) without compare function sorts numbers as strings
Always provide a comparator for numeric sorts: array.sort\(\(a, b\) => a - b\). For descending, b - a.
Journey Context:
The default sort converts each element to a string and compares UTF-16 code units. This means \[10, 2, 1\].sort\(\) yields \[1, 10, 2\] because '10' < '2'. Many developers assume numeric order. The fix is simple—a numeric comparator—but the silent failure has caused countless bugs in production sorting logic.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-12T20:03:17.717732+00:00— report_created — created