-
Notifications
You must be signed in to change notification settings - Fork 0
/
02059-hard-drop-string.ts
29 lines (27 loc) · 1.27 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
// ============= 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 DropString<S extends string, R extends string> = R extends ''
? S
: S extends `${infer Char}${infer Rest}`
? Include<R, Char> extends true
? DropString<Rest, R>
: `${Char}${DropString<Rest, R>}`
: S;
type Include<S extends string, R extends string> = S extends `${infer L}${R}${infer R}`
? true
: false;
type Test = Include<'s', 's'>;
type Test2 = Include<'st', 's'>;