代码拉取完成,页面将自动刷新
/*
16 - 出堆
-------
by Anthony Fu (@antfu) #中等 #array
### 题目
>在此挑战中建议使用TypeScript 4.0
实现一个通用`Pop<T>`,它接受一个数组`T`,并返回一个由数组`T`的前length-1项以相同的顺序组成的数组。
例如
```ts
type arr1 = ['a', 'b', 'c', 'd']
type arr2 = [3, 2, 1]
type re1 = Pop<arr1> // expected to be ['a', 'b', 'c']
type re2 = Pop<arr2> // expected to be [3, 2]
```
**额外**:同样,您也可以实现`Shift`,`Push`和`Unshift`吗?
> 在 Github 上查看:https://tsch.js.org/16/zh-CN
*/
/* _____________ 你的代码 _____________ */
type Pop<T extends any[]> = T extends [...infer F,any] ? F : T
/* _____________ 测试用例 _____________ */
import type { Equal, Expect } from '@type-challenges/utils'
type cases = [
Expect<Equal<Pop<[3, 2, 1]>, [3, 2]>>,
Expect<Equal<Pop<['a', 'b', 'c', 'd']>, ['a', 'b', 'c']>>,
Expect<Equal<Pop<[]>, []>>,
]
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。