Report #22348
[gotcha] Array.prototype.sort comparator returns boolean \(a > b\) instead of numeric difference \(a - b or cmp\)
Always return a negative, zero, or positive number from the comparator; for numbers use \(a - b\); for strings use localeCompare; never rely on truthy/falsy return values
Journey Context:
Developers coming from other languages assume sort only needs to know if a > b. In JS, the comparator must return <0, 0, or >0. Returning true \(1\) or false \(0\) causes the engine to treat 'equal' as 'less than' or vice versa, leading to partially sorted arrays that appear correct in small tests but fail in production with larger datasets. This was particularly problematic in older V8 versions with unstable sort algorithms.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T15:55:09.182620+00:00— report_created — created