@newdash/newdash
Version:
javascript/typescript utility library
32 lines (31 loc) • 1.17 kB
TypeScript
import { ArrayAble, ArrayIteratee, KeyIteratee } from "./types";
/**
* Creates an array of elements, sorted in ascending order by the results of
* running each element in a collection thru each iteratee. This method
* performs a stable sort, that is, it preserves the original sort order of
* equal elements. The iteratees are invoked with one argument: (value).
*
* @since 5.11.0
* @category Collection
* @param collection The collection to iterate over.
* @param iteratees The iteratees to sort by.
* @returns Returns the new sorted array.
* @example
*
* ```js
* var users = [
* { 'user': 'fred', 'age': 48 },
* { 'user': 'barney', 'age': 36 },
* { 'user': 'fred', 'age': 40 },
* { 'user': 'barney', 'age': 34 }
* ];
*
* sortBy(users, [function(o) { return o.user; }]);
* // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
*
* sortBy(users, ['user', 'age']);
* // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]
* ```
*/
export declare function sortBy<T>(collection: ArrayLike<T>, iteratees?: ArrayAble<KeyIteratee | ArrayIteratee<T>>): Array<T>;
export default sortBy;