"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var getArraySortNumber_1 = __importDefault(require("../array/getArraySortNumber"));
/**
* Sort table rows data with a "sort state" array
* @category algo
* @module sortTableRowsByEachCell
*/
function sortTableRowsByEachCell(rows, sortState, comparator) {
var reversedSortState = __spreadArray([], sortState, true).reverse();
return reversedSortState.reduce(function (sortedRow, cellSortState) {
var index = cellSortState.index, isDescending = cellSortState.isDescending;
return sortedRow.sort(function (a, b) {
var sortNum = comparator
? comparator(a, b, index)
: (0, getArraySortNumber_1.default)(a, b);
return sortNum * (isDescending ? -1 : 1);
});
}, __spreadArray([], rows, true));
}
exports.default = sortTableRowsByEachCell;
Source