UNPKG

@bigfishtv/cockpit

Version:

27 lines (25 loc) 586 B
export function sortProperty(property) { var direction = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'asc'; var LT = direction === 'asc' ? -1 : 1; var GT = direction === 'asc' ? 1 : -1; return function (a, b) { if (a[property] === b[property]) { return 0; } else if (a[property] < b[property]) { return LT; } else { return GT; } }; } export function multisort(funcs) { return function (a, b) { for (var i = 0; i < funcs.length; i++) { var result = funcs[i](a, b); if (result !== 0) { return result; } } return 0; }; }