opt-table
Version:
A Responsive and Customizable Rich Table
26 lines • 955 B
JavaScript
export function getComparator(order, orderBy) {
return order === "desc"
? (a, b) => descendingComparator(a, b, orderBy)
: (a, b) => -descendingComparator(a, b, orderBy);
}
function descendingComparator(a, b, orderBy) {
if (b[orderBy] < a[orderBy]) {
return -1;
}
if (b[orderBy] > a[orderBy]) {
return 1;
}
return 0;
}
export function stableSort(array, comparator) {
const stabilizedThis = array === null || array === void 0 ? void 0 : array.map((el, index) => [el, index]);
stabilizedThis === null || stabilizedThis === void 0 ? void 0 : stabilizedThis.sort((a, b) => {
const order = comparator(a[0], b[0]);
if (order !== 0) {
return order;
}
return a[1] - b[1];
});
return stabilizedThis === null || stabilizedThis === void 0 ? void 0 : stabilizedThis.map((el) => el[0]);
}
//# sourceMappingURL=table_utils.js.map