Skip to content

sortBy() function

Returns an array which sorted according to the f.

Signature:

typescript
declare function sortBy(f: (a: any) => unknown, iterable: readonly []): any[];

Example

ts
sortBy(a => a, [3, 4, 1, 2, 5, 2]);
// [1, 2, 2, 3, 4, 5]
sortBy((a) => a.id, [{id:4,name:'foo'}, {id:2,name:'bar'},{id:3, name:'lee'}]);
// [{id:2,name:'bar'}, {id:3, name:'lee'}, {id:4,name:'foo'}]

Open Source Code

Released under the Apache-2.0 License.