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 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | 1x 1x 2x 2x 2x 2x | import { purry } from './purry'; /** * Sorts an array. The comparator function should accept two values at a time and return a negative number if the first value is smaller, a positive number if it's larger, and zero if they are equal. * @param items the array to sort * @param cmp the comparator function * @signature * R.sort(items, cmp) * @example * R.sort([4, 2, 7, 5], (a, b) => a - b) // => [2, 4, 5, 7] * @data_first * @category Array */ export function sort<T>(items: T[], cmp: (a: T, b: T) => number): T[]; /** * Sorts an array. The comparator function should accept two values at a time and return a negative number if the first value is smaller, a positive number if it's larger, and zero if they are equal. * @param cmp the comparator function * @signature * R.sort(cmp)(items) * @example * R.pipe([4, 2, 7, 5], R.sort((a, b) => a - b)) // => [2, 4, 5, 7] * @data_last * @category Array */ export function sort<T>(cmp: (a: T, b: T) => number): (items: T[]) => T[]; export function sort<T>() { return purry(_sort, arguments); } function _sort<T>(items: T[], cmp: (a: T, b: T) => number) { const ret = [...items]; ret.sort(cmp); return ret; } |