代码拉取完成,页面将自动刷新
/*
459 - Flatten
-------
by zhouyiming (@chbro) #中等 #array
### 题目
在这个挑战中,你需要写一个接受数组的类型,并且返回扁平化的数组类型。
例如:
```ts
type flatten = Flatten<[1, 2, [3, 4], [[[5]]]]> // [1, 2, 3, 4, 5]
```
> 在 Github 上查看:https://tsch.js.org/459/zh-CN
*/
/* _____________ 你的代码 _____________ */
type Flatten<T extends any[]> = T extends [infer F , ...infer R] ? F extends any[] ? [...Flatten<F>,...Flatten<R>] : [F,...Flatten<R>] : []
/* _____________ 测试用例 _____________ */
import type { Equal, Expect } from '@type-challenges/utils'
type cases = [
Expect<Equal<Flatten<[]>, []>>,
Expect<Equal<Flatten<[1, 2, 3, 4]>, [1, 2, 3, 4]>>,
Expect<Equal<Flatten<[1, [2]]>, [1, 2]>>,
Expect<Equal<Flatten<[1, 2, [3, 4], [[[5]]]]>, [1, 2, 3, 4, 5]>>,
Expect<Equal<Flatten<[{ foo: 'bar'; 2: 10 }, 'foobar']>, [{ foo: 'bar'; 2: 10 }, 'foobar']>>,
]
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。