Sequence
介绍
对字符串数组,进行排列和组合
ts
type A = Subsequence<[1, 2]> // [] | [1] | [2] | [1, 2]
View on GitHubts
type A = Subsequence<[1, 2]> // [] | [1] | [2] | [1, 2]
起点
ts
/* _____________ Your Code Here _____________ */typeSubsequence <T extends any[]> = any/* _____________ Test Cases _____________ */typecases = [Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.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]>, [] |[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] >>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <Subsequence <['a', 'b', 'c']>, [] |['a'] | ['b'] | ['c'] |['a', 'b'] | ['a', 'c'] | ['b', 'c'] |['a', 'b', 'c'] >>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <Subsequence <['x', 'y']>, [] |['x'] | ['y'] |['x', 'y'] >>,]
take the challengets
/* _____________ Your Code Here _____________ */typeSubsequence <T extends any[]> = any/* _____________ Test Cases _____________ */typecases = [Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.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]>, [] |[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] >>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <Subsequence <['a', 'b', 'c']>, [] |['a'] | ['b'] | ['c'] |['a', 'b'] | ['a', 'c'] | ['b', 'c'] |['a', 'b', 'c'] >>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <Subsequence <['x', 'y']>, [] |['x'] | ['y'] |['x', 'y'] >>,]
解决方案
Spoiler warning // Click to reveal answer
ts
typeSubsequence <T extends any[]> = any
ts
typeSubsequence <T extends any[]> = any