Report #85334
[gotcha] Sorting BigInt arrays with arithmetic comparator throws TypeError or corrupts ordering
Use a comparator function returning explicit -1/0/1 \(e.g., \(a, b\) => \(a < b ? -1 : a > b ? 1 : 0\)\). Never use \(a, b\) => a - b.
Journey Context:
Array.prototype.sort expects a Number from the comparator. If you return a BigInt \(from a - b\), the spec coerces it via ToNumber, which throws for BigInt. If you mistakenly convert to Number for the comparison, large BigInts lose precision and sort incorrectly. Explicit three-way comparison is the only safe pattern.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T01:49:14.656739+00:00— report_created — created