MCPcopy Create free account
hub / github.com/dunky11/react-saas-template / stableSort

Function stableSort

src/shared/functions/stableSort.js:1–9  ·  view source on GitHub ↗
(array, cmp)

Source from the content-addressed store, hash-verified

1function stableSort(array, cmp) {
2 const stabilizedThis = array.map((el, index) => [el, index]);
3 stabilizedThis.sort((a, b) => {
4 const order = cmp(a[0], b[0]);
5 if (order !== 0) return order;
6 return a[1] - b[1];
7 });
8 return stabilizedThis.map(el => el[0]);
9}
10export default stableSort;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected