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"]