首页 > 其他分享 >[Typescript] 83. Medium - Subsequence

[Typescript] 83. Medium - Subsequence

时间:2022-10-31 15:14:43浏览次数:105  
标签:elements _____________ Subsequence Typescript Expect 83 type

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] >>,
]

 

标签:elements,_____________,Subsequence,Typescript,Expect,83,type
From: https://www.cnblogs.com/Answer1215/p/16844300.html

相关文章