代码拉取完成,页面将自动刷新
/*
2059 - Drop String
-------
by CaptainOfPhB (@CaptainOfPhB) #hard #template-literal #infer
### Question
Drop the specified chars from a string.
For example:
```ts
type Butterfly = DropString<'foobar!', 'fb'> // 'ooar!'
```
> View on GitHub: https://tsch.js.org/2059
*/
/* _____________ Your Code Here _____________ */
type ConvertStringToUnionType<R extends string,S extends string | undefined = undefined> = R extends `${infer L}${infer N}` ? N extends '' ? S | L : ConvertStringToUnionType<N,S | L> : never
type test = ConvertStringToUnionType<'1234'>
type DropString<S extends string, R extends string> = S extends `${infer L}${ConvertStringToUnionType<R>}${infer N}` ? DropString<`${L}${N}`,R> : S
/* _____________ Test Cases _____________ */
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 ! '>>,
]
/* _____________ Further Steps _____________ */
/*
> Share your solutions: https://tsch.js.org/2059/answer
> View solutions: https://tsch.js.org/2059/solutions
> More Challenges: https://tsch.js.org
*/
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。