Skip to content

sort() function

Returns an array, sorted according to the comparator f, which should accept two values

Signature:

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

Example

ts
sort((a, b) => a > b, [3, 4, 1, 2, 5, 2]); // [1, 2, 2, 3, 4, 5]
sort((a, b) => a.localeCompare(b), "bcdaef"); // ["a", "b", "c", "d", "e", "f"]

Open Source Code

Released under the Apache-2.0 License.