Type Challenges Judge

Split

提出詳細

type Split<S extends string, SEP extends string, Tmp extends string = "", Res extends string[] = []> = S extends `${infer L}` ? SEP extends "" ? S extends `${infer L}${infer R}` ? Split<R, SEP, "", [...Res, L]> : Res : S extends `${SEP}${infer R}` ? Split<R, SEP, "", [...Res, Tmp]> : S extends `${infer L}${infer R}` ? Split<R, SEP, `${Tmp}${L}`, Res> : [...Res, Tmp] : string[]
提出日時2023-08-08 17:26:33
問題Split
ユーザーookkoouu
ステータス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[]>>, ]