[Typescript] 115. Hard - Drop String
Drop the specified chars from a string.
For example:
type Butterfly = DropString<'foobar!', 'fb'> // 'ooar!'
/* _____________ Your Code Here _____________ */
type StringToUnion<S> = S extends `${infer F}${infer RT}` ? F | StringToUnion<RT>: never;
type DropString<S, R> = R extends '' ? S : S extends `${infer F}${infer RT}`
? F extends StringToUnion<R> ? DropString<RT, R>: `${F}${ DropString<RT, 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 ! '>>,
]
分类:
TypeScript
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2019-11-25 [ARIA] aria-describedby & aria-labelledby
2019-11-25 [Security] Always use parameterized queries
2016-11-25 [Ramda] Handle Branching Logic with Ramda's Conditional Functions
2016-11-25 [Angular2 Router] Setup page title with Router events
2015-11-25 [Redux] Store Methods: getState(), dispatch(), and subscribe()
2015-11-25 [Redux] Introduction
2014-11-25 [AngularJS] Best Practise - Minification and annotation