hd-utils
Version:
A handy utils for modern JS developers
16 lines (15 loc) • 564 B
TypeScript
import { Key } from '../utilityTypes';
type SortArrOptions<T> = {
key?: Key;
desc?: boolean;
getValue?: (v: T) => Key;
};
/**
* @description It sorts an array of objects or strings or numbers, and if the array is an array of objects, it can
* sort by a key of the objects.
* @example sortArr([4,2,1]) // [1,2,4]
* @example sortArr([{a:2}, {a:1}], {key:"a"}) // [{a:1}, {a:2}]
* @example sortArr([{a:2}, {a:1}], {getValue:(v) => v.a}) // [{a:1}, {a:2}]
*/
export default function sortArr<T>(arr: T[], options?: SortArrOptions<T>): T[];
export {};