Skip to content

sort() function

두 값을 받아야 하는 비교자 f에 따라 정렬된 배열을 반환합니다.

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.