1 Star 1 Fork 0

wangzichu/ts-challenges

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
8987.Subsequence.ts 1.16 KB
一键复制 编辑 原始数据 按行查看 历史
王子初 提交于 2023-04-28 17:23 . 提交更新
/*
8987 - Subsequence
-------
by jiangshan (@jiangshanmeta) #medium #union
### Question
Given an array of unique elements, return all possible subsequences.
A subsequence is a sequence that can be derived from an array by deleting some or no elements without changing the order of the remaining elements.
For example:
```typescript
type A = Subsequence<[1, 2]> // [] | [1] | [2] | [1, 2]
```
> View on GitHub: https://tsch.js.org/8987
*/
/* _____________ Your Code Here _____________ */
type Subsequence<T extends any[],Prefix extends any[] = []> = T extends [infer F,...infer R]? Subsequence<R,Prefix | [...Prefix,F]>:Prefix
type test = Subsequence<[1,2]>
/* _____________ Test Cases _____________ */
import type { Equal, Expect } from '@type-challenges/utils'
type cases = [
Expect<Equal<Subsequence<[1, 2]>, [] | [1] | [2] | [1, 2]>>,
Expect<Equal<Subsequence<[1, 2, 3]>, [] | [1] | [2] | [1, 2] | [3] | [1, 3] | [2, 3] | [1, 2, 3] >>,
]
/* _____________ Further Steps _____________ */
/*
> Share your solutions: https://tsch.js.org/8987/answer
> View solutions: https://tsch.js.org/8987/solutions
> More Challenges: https://tsch.js.org
*/
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wang-zichu/ts-challenges.git
git@gitee.com:wang-zichu/ts-challenges.git
wang-zichu
ts-challenges
ts-challenges
master

搜索帮助