Split
提出詳細
type Split<S extends string, SEP extends string=never, Acc extends readonly unknown []=[]> = [SEP] extends [never] ? [S] : string extends S ? string[] : S extends `${infer S1}${SEP}${infer S2}` ? Split<S2,SEP,[...Acc, S1]> : Acc extends [] ? SEP extends "" ? [] : [S] : S extends "" ? Acc : [...Acc, S]
提出日時 | 2023-09-22 13:43:36 |
---|---|
問題 | Split |
ユーザー | sankantsu |
ステータス | Accepted |
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<Split<'Hi! How are you?', 'z'>, ['Hi! How are you?']>>, Expect<Equal<Split<'Hi! How are you?', ' '>, ['Hi!', 'How', 'are', 'you?']>>, Expect<Equal<Split<'Hi! How are you?', ''>, ['H', 'i', '!', ' ', 'H', 'o', 'w', ' ', 'a', 'r', 'e', ' ', 'y', 'o', 'u', '?']>>, Expect<Equal<Split<'', ''>, []>>, Expect<Equal<Split<'', 'z'>, ['']>>, Expect<Equal<Split<string, 'whatever'>, string[]>>, ]