Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 3x 8x 4x 5x 5x 8x | import {KeyProjection} from 'fnxt/fnxt-types'; /** * @deprecated use fnxt/array/sortWith * @param fn */ export const sortBy = <T>(fn: KeyProjection<T>) => (array: T[]): T[] => { const tuples = array.map(e => [fn(e), e]); return (tuples // @ts-ignore .sort((tuples[0] && typeof tuples[0][0] === 'number') ? ((a: [number, T], b: [number, T]) => a[0] - b[0]) : ((a: [string, T], b: [string, T]) => a[0].localeCompare(b[0])) ) as [number, T][] | [string, T][]) .map((e: [number | string, T]) => e[1]) as T[]; }; |