Drop String
提出詳細
type SplitUnion<S extends string> = S extends `${infer L}${infer R}` ? L | SplitUnion<R> : never type DropString<S extends string, R extends string, Acc extends string = ""> = S extends "" ? Acc : S extends `${SplitUnion<R>}${infer Rest}` ? DropString<Rest, R, `${Acc}`> : S extends `${infer L}${infer Rest}` ? DropString<Rest, R, `${Acc}${L}`> : never
提出日時 | 2024-09-12 15:14:48 |
---|---|
問題 | Drop String |
ユーザー | ookkoouu |
ステータス | Accepted |
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<DropString<'butter fly!', ''>, 'butter fly!'>>, Expect<Equal<DropString<'butter fly!', ' '>, 'butterfly!'>>, Expect<Equal<DropString<'butter fly!', 'but'>, 'er fly!'>>, Expect<Equal<DropString<' b u t t e r f l y ! ', 'but'>, ' e r f l y ! '>>, Expect<Equal<DropString<' butter fly! ', ' '>, 'butterfly!'>>, Expect<Equal<DropString<' b u t t e r f l y ! ', ' '>, 'butterfly!'>>, Expect<Equal<DropString<' b u t t e r f l y ! ', 'but'>, ' e r f l y ! '>>, Expect<Equal<DropString<' b u t t e r f l y ! ', 'tub'>, ' e r f l y ! '>>, Expect<Equal<DropString<' b u t t e r f l y ! ', 'b'>, ' u t t e r f l y ! '>>, Expect<Equal<DropString<' b u t t e r f l y ! ', 't'>, ' b u e r f l y ! '>>, ]