Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function desc(a, b, orderBy) {
- if (b[orderBy] < a[orderBy]) {
- return -1;
- }
- if (b[orderBy] > a[orderBy]) {
- return 1;
- }
- return 0;
- }
- function stableSort(array, cmp) {
- const stabilizedThis = array.map((el, index) => [el, index]);
- stabilizedThis.sort((a, b) => {
- const order = cmp(a[0], b[0]);
- if (order !== 0) return order;
- return a[1] - b[1];
- });
- return stabilizedThis.map(el => el[0]);
- }
- function getSorting(order, orderBy) {
- return order === 'desc' ? (a, b) => desc(a, b, orderBy) : (a, b) => -desc(a, b, orderBy);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement