UNPKG

@bigfishtv/cockpit

Version:

26 lines (24 loc) 497 B
export function sortProperty(property, direction = 'asc') { const LT = direction === 'asc' ? -1 : 1 const GT = direction === 'asc' ? 1 : -1 return (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 (a, b) => { for (let i = 0; i < funcs.length; i++) { const result = funcs[i](a, b) if (result !== 0) { return result } } return 0 } }