diff --git a/app/src/helpers.ts b/app/src/helpers.ts index 372001e1..6f156561 100644 --- a/app/src/helpers.ts +++ b/app/src/helpers.ts @@ -34,3 +34,15 @@ export function isNullishOrEmpty(obj: any) { export function isEmptyArray(obj: any) { return Array.isArray(obj) && obj.length === 0; } + +type AccessorFunction = (obj: T) => V; + +type CompareFunction = (a: T, b: T) => number; + +export function numAsc(accessor: AccessorFunction): CompareFunction{ + return (a: T, b: T) => Number(accessor(a) - accessor(b)); +} + +export function numDesc(accessor: AccessorFunction): CompareFunction { + return (a: T, b: T) => Number(accessor(b) - accessor(a)); +}