Report #98258
[gotcha] Array.prototype.sort\(\) coerces numbers to strings by default, so \[10, 2, 1\].sort\(\) returns \[1, 10, 2\]
Always pass an explicit comparator for non-string data: \[10, 2, 1\].sort\(\(a, b\) => a - b\). For mixed types or strings, decide whether lexicographic or numeric ordering is intended and never rely on the default.
Journey Context:
The default comparator effectively stringifies elements, a legacy behavior from early JS. Developers assume sort means numeric ordering and get silently wrong results in dashboards, leaderboards, and tables. We considered defaulting to numeric in tutorials, but the spec is fixed. The right call is to treat sort\(\) as only correct for strings and pass a comparator everywhere else.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-27T04:39:58.275478+00:00— report_created — created