跳到主要内容

Sequence

介绍

对字符串数组,进行排列和组合

ts
type A = Subsequence<[1, 2]> // [] | [1] | [2] | [1, 2]
ts
type A = Subsequence<[1, 2]> // [] | [1] | [2] | [1, 2]
View on GitHub

起点

ts
/* _____________ Your Code Here _____________ */
 
type Subsequence<T extends any[]> = any
 
/* _____________ Test Cases _____________ */
type cases = [
Expect<Equal<Subsequence<[1, 2]>, [] | [1] | [2] | [1, 2]>>,
Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.
Expect<Equal<Subsequence<[1, 2, 3]>, [] | [1] | [2] | [1, 2] | [3] | [1, 3] | [2, 3] | [1, 2, 3]>>,
Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.
Expect<Equal<Subsequence<[1, 2, 3, 4, 5]>, [] |
Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.
[1] | [2] | [3] | [4] | [5] |
[1, 2] | [1, 3] | [1, 4] | [1, 5] | [2, 3] | [2, 4] | [2, 5] | [3, 4] | [3, 5] | [4, 5] |
[1, 2, 3] | [1, 2, 4] | [1, 2, 5] | [1, 3, 4] | [1, 3, 5] | [1, 4, 5] | [2, 3, 4] | [2, 3, 5] | [2, 4, 5] | [3, 4, 5] |
[1, 2, 3, 4] | [1, 2, 3, 5] | [1, 2, 4, 5] | [1, 3, 4, 5] | [2, 3, 4, 5] |
[1, 2, 3, 4, 5] >>,
Expect<Equal<Subsequence<['a', 'b', 'c']>, [] |
Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.
['a'] | ['b'] | ['c'] |
['a', 'b'] | ['a', 'c'] | ['b', 'c'] |
['a', 'b', 'c'] >>,
Expect<Equal<Subsequence<['x', 'y']>, [] |
Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.
['x'] | ['y'] |
['x', 'y'] >>,
]
 
ts
/* _____________ Your Code Here _____________ */
 
type Subsequence<T extends any[]> = any
 
/* _____________ Test Cases _____________ */
type cases = [
Expect<Equal<Subsequence<[1, 2]>, [] | [1] | [2] | [1, 2]>>,
Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.
Expect<Equal<Subsequence<[1, 2, 3]>, [] | [1] | [2] | [1, 2] | [3] | [1, 3] | [2, 3] | [1, 2, 3]>>,
Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.
Expect<Equal<Subsequence<[1, 2, 3, 4, 5]>, [] |
Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.
[1] | [2] | [3] | [4] | [5] |
[1, 2] | [1, 3] | [1, 4] | [1, 5] | [2, 3] | [2, 4] | [2, 5] | [3, 4] | [3, 5] | [4, 5] |
[1, 2, 3] | [1, 2, 4] | [1, 2, 5] | [1, 3, 4] | [1, 3, 5] | [1, 4, 5] | [2, 3, 4] | [2, 3, 5] | [2, 4, 5] | [3, 4, 5] |
[1, 2, 3, 4] | [1, 2, 3, 5] | [1, 2, 4, 5] | [1, 3, 4, 5] | [2, 3, 4, 5] |
[1, 2, 3, 4, 5] >>,
Expect<Equal<Subsequence<['a', 'b', 'c']>, [] |
Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.
['a'] | ['b'] | ['c'] |
['a', 'b'] | ['a', 'c'] | ['b', 'c'] |
['a', 'b', 'c'] >>,
Expect<Equal<Subsequence<['x', 'y']>, [] |
Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.
['x'] | ['y'] |
['x', 'y'] >>,
]
 
take the challenge

解决方案

Spoiler warning // Click to reveal answer
ts
type Subsequence<T extends any[]> = any
 
ts
type Subsequence<T extends any[]> = any
 
view more solutions