@newdash/newdash
Version:
javascript/typescript utility library
34 lines (33 loc) • 822 B
TypeScript
type Indexer<T = any> = (v: T) => number;
/**
* hash sort function
*
* @since 5.21.0
* @param collection array collection
* @param indexer extract numeric index from each item of collection
* @param reverse reverse the sort order (DESC)
* @returns the sorted list
*
* @example
*
* ```js
* hashSort([2, 999, 3, 113, 3, 32, 3, 4])
* // [2, 3, 3, 3, 4, 32, 113, 999]
*
* hashSort(
[
{ age: 2 },{ age: 999 },{ age: 3 },
{ age: 113 },{ age: 3 },{ age: 32 },
{ age: 3 },{ age: 4 }
],
(item) => item.age
)
// [
// { age: 2 },{ age: 3 },{ age: 3 },
// { age: 3 },{ age: 4 },{ age: 32 },
// { age: 113 },{ age: 999 }
// ]
* ```
*/
export declare function hashSort<T>(collection: Array<T>, indexer?: Indexer<T>, reverse?: boolean): Array<T>;
export default hashSort;