-
Notifications
You must be signed in to change notification settings - Fork 0
/
02059-hard-drop-string.ts
40 lines (36 loc) · 1.25 KB
/
02059-hard-drop-string.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// ============= Test Cases =============
import type { Equal, Expect } from './test-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 ! '>>
]
// ============= Your Code Here =============
type DropChar<
T extends string,
U extends string
> = T extends `${infer Head}${U}${infer Tail}`
? DropChar<`${Head}${Tail}`, U>
: T
type DropString<
T extends string,
U extends string
> = U extends `${infer Head}${infer Tail}`
? DropString<DropChar<T, Head>, Tail>
: T
type Test = DropString<'b u t t e r f l y ! ', 'bu'>