首页 > 其他分享 >[Typescript] 44. Medium - Drop char

[Typescript] 44. Medium - Drop char

时间:2022-10-07 01:22:39浏览次数:48  
标签:butterfly Typescript _____________ 44 DropChar char Expect type

Drop a specified char from a string.

For example:

type Butterfly = DropChar<' b u t t e r f l y ! ', ' '> // 'butterfly!'

 

/* _____________ Your Code Here _____________ */

type DropChar<S extends string, C extends string, ACC extends string = ''> = S extends `${infer P}${infer REST}` 
  ? P extends C 
    ? DropChar<REST, C, ACC> 
    : `${ACC}${P}${DropChar<REST, C, ACC>}`
  : ACC

/* _____________ Test Cases _____________ */
import type { Equal, Expect } from '@type-challenges/utils'

type cases = [
  // @ts-expect-error
  Expect<Equal<DropChar<'butter fly!', ''>, 'butterfly!'>>,
  Expect<Equal<DropChar<'butter fly!', ' '>, 'butterfly!'>>,
  Expect<Equal<DropChar<'butter fly!', '!'>, 'butter fly'>>,
  Expect<Equal<DropChar<'    butter fly!        ', ' '>, 'butterfly!'>>,
  Expect<Equal<DropChar<' b u t t e r f l y ! ', ' '>, 'butterfly!'>>,
  Expect<Equal<DropChar<' b u t t e r f l y ! ', 'b'>, '  u t t e r f l y ! '>>,
  Expect<Equal<DropChar<' b u t t e r f l y ! ', 't'>, ' b u   e r f l y ! '>>,
]

 

标签:butterfly,Typescript,_____________,44,DropChar,char,Expect,type
From: https://www.cnblogs.com/Answer1215/p/16758969.html

相关文章

  • TypeScript
    学习文档:https://www.runoob.com/typescript/ts-tutorial.htmlTypeScript是JavaScript的一个超集(js的扩展),支持ECMAScript6标准1.安装使用国内镜像:npmconfigset......
  • 前端Axios-Day44
    JSONServer:模拟服务器环境插件1.进行全局安装:npmi-gjson-server2.创建db.json文件并写入相关数据:{"posts":[{"id":1,"title":"json-server","author......
  • HDU4417 Super Mario (主席树)
    主席树另一模板。查询的是[L,R]中<=h的个数。1#include<bits/stdc++.h>2usingnamespacestd;3#definelctr[i].ch[0]4#definerctr[i].ch[1]5#define......
  • Pyecharts基本图的使用
    概况:Echarts是一个由百度开源的数据可视化,凭借着良好的交互性,精巧的图表设计,得到了众多开发者的认可。而Python是一门富有表达力的语言,很适合用于数据处理。当数据分析......
  • 【CS144】Spongeの类图分析(lab0~lab4)
    lab4写不下去了,感觉对代码理不清了,打算重新整理一下。重点是五个类,(正好对应lab0~lab4)ByteStream类这里只展示startcode中类的模样(具体的实现可能各有不同,所以重点看函......
  • [Typescript] 43. Medium - Percentage Parser
    ImplementPercentageParser.Accordingtothe /^(\+|\-)?(\d*)?(\%)?$/ regularitytomatchTandgetthreematches.Thestructureshouldbe:[plusorminus, n......
  • 错误: 操作符不存在: integer = character varying 建议:没有匹配指定名称和参数类型
    postgresql对变量类型比较敏感,对相应的变量进行类型转换之后就可以了修改前:<iftest="lx!=nullandlx.size>0">ANDt.lxin<foreachcollect......
  • switch,putchar,getchar
    今天主要自学了switch,putchar,getchar语句加深了一下理解#include<stdio.h>intmain(){ intch; while((ch=getchar())!=EOF)//getchar接受字符 { putchar(ch);......
  • TypeScript中typeof的简单介绍
    简单介绍typeof我们都知道js提供了typeof,用来获取基本数据的类型。实际上,TS也提供了typeof操作符。可以在【类型上下文】中进行类型查询。只能够进行变量或者属性查......
  • PyCharm安装PyQt5及其工具(Qt Designer、PyUIC、PyRcc)详细教程
    摘要:Qt是常用的用户界面设计工具,而在Python中则使用PyQt这一工具包,它是Python编程语言和Qt库的成功融合。这篇博文通过图文详细介绍在PyCharm中如何完整优雅地安装配置P......