Type Challenges Judge

Drop String

提出詳細

type Contains<S extends string, C extends string> = S extends `${infer S1}${infer S2}` ? S1 extends C ? true : Contains<S2,C> : false type DropString<S extends string, R extends string> = S extends `${infer S1}${infer S2}` ? Contains<R,S1> extends true ? DropString<S2,R> : `${S1}${DropString<S2,R>}` : ""
提出日時2023-09-19 05:19:31
問題Drop String
ユーザーsankantsu
ステータス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 ! '>>, ]