[Typescript] 83. Medium - Subsequence
typescript Medium Subsequence 83
2023-09-14 08:59:11 时间
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:
type A = Subsequence<[1, 2]> // [] | [1] | [2] | [1, 2]
/* _____________ Your Code Here _____________ */
type Subsequence<T extends any[]> = T extends [infer F, ...infer RT]
? Subsequence<RT> | [F, ...Subsequence<RT>]
: []
/* _____________ 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] >>,
]
相关文章
- javascript typescript_typescript python
- 前端 QA 工具链指南 - husky,commitlint,commitizen,eslint,typescript,express
- TypeScript学习笔记(二)—— TypeScript基础
- TypeScript:Uncaught TypeError: Cannot read properties of null 错误
- 快速掌握 TypeScript 新语法:infer extends
- 在 Typescript 中使用 Array.filter(Boolean)
- 【工程搭建】从零搭建一个 typescript + express + eslint 工程
- Vue 3 + Typescript + Vite 基个人网站二维码登录功能
- TypeScript 中 as const 是什么
- TypeScript 类型体操:合并映射类型的处理结果为联合类型
- 关于 2022 年 JavaScript 生态调查报告:TypeScript持续主导,Vite和Tauri大受欢迎
- TypeScript 中提升幸福感的 10 个高级技巧
- 【TypeScript】条件语句
- TypeScript 5.0 现已发布:全新的装饰器,速度、内存和包大小优化
- 调查:React 仍然是使用最广泛的前端框架,TypeScript 是优先选项
- 如何发布一个 TypeScript 编写的 npm 包
- 开心档之TypeScript 联合类型
- 在TypeScript中使用装饰器