The ECMAScript standard does not guarantee Array.sort
is a stable sort. Chrome (the V8 engine) uses in-place QuickSort internally (for arrays of size ≥ 22, else insertion sort) which is fast but not stable.
To fix it, make customSort
compare with .b
as well, eliminating the need of stability of the sorting algorithm.