Skip to content

Commit d6cdada

Browse files
committed
feat: add 2059-hard-drop-string
1 parent 220e2d3 commit d6cdada

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// 参考 https://github.com/type-challenges/type-challenges/issues/10004
2+
type MyStringToUnion<
3+
T extends string,
4+
U extends string = never
5+
> = T extends `${infer F}${infer Rest}` ? MyStringToUnion<Rest, U | F> : U;
6+
7+
type DropString<
8+
S extends string,
9+
U extends string,
10+
R extends string = ""
11+
> = S extends `${infer F}${infer Rest}`
12+
? F extends MyStringToUnion<U>
13+
? DropString<Rest, U, R>
14+
: DropString<Rest, U, `${R}${F}`>
15+
: R;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type { Equal, Expect } from "@type-challenges/utils";
2+
3+
type cases = [
4+
Expect<Equal<DropString<"butter fly!", "">, "butter fly!">>,
5+
Expect<Equal<DropString<"butter fly!", " ">, "butterfly!">>,
6+
Expect<Equal<DropString<"butter fly!", "but">, "er fly!">>,
7+
Expect<
8+
Equal<DropString<" b u t t e r f l y ! ", "but">, " e r f l y ! ">
9+
>,
10+
Expect<Equal<DropString<" butter fly! ", " ">, "butterfly!">>,
11+
Expect<Equal<DropString<" b u t t e r f l y ! ", " ">, "butterfly!">>,
12+
Expect<
13+
Equal<DropString<" b u t t e r f l y ! ", "but">, " e r f l y ! ">
14+
>,
15+
Expect<
16+
Equal<DropString<" b u t t e r f l y ! ", "tub">, " e r f l y ! ">
17+
>,
18+
Expect<
19+
Equal<DropString<" b u t t e r f l y ! ", "b">, " u t t e r f l y ! ">
20+
>,
21+
Expect<Equal<DropString<" b u t t e r f l y ! ", "t">, " b u e r f l y ! ">>
22+
];

0 commit comments

Comments
 (0)