This implements the Lisp decorate-sort-undecorate pattern (aka Schwartzian transform): it first maps
all the elements, then sorts by the mapped value, and then returns an array of the original elements.
If two elements map to the same value, the original element order is preserved.
A stable array sort using a mapping function.
This implements the Lisp decorate-sort-undecorate pattern (aka Schwartzian transform): it first maps all the elements, then sorts by the mapped value, and then returns an array of the original elements. If two elements map to the same value, the original element order is preserved.