175. 数字排序

极难0

实现一个高级工具类型 Sort ,对自然数数组进行排序,可以是升序排序,也可以是降序排序。

升序排序示例:

type Res1 = Sort<[]> // expected to be []
type Res2 = Sort<[1]> // expected to be [1]
type Res3 = Sort<[2, 4, 7, 6, 6, 6, 5, 8, 9]> // expected to be [2, 4, 5, 6, 6, 6, 7, 8, 9]

Sort 类型还应该接受一个布尔类型的参数。当参数为 true 时,排序结果应为降序排序。示例如下:

type Res1 = Sort<[3, 2, 1], true> // expected to be [3, 2, 1]
type Res2 = Sort<[3, 2, 0, 1, 0, 0, 0], true> // expected to be [3, 2, 1, 0, 0, 0, 0]

额外挑战:

  1. 支持超过 15 位的自然数。
  2. 支持浮点数。
评论(0)
题库

TypeScript

加载中...