代码拉取完成,页面将自动刷新
/*
2693 - EndsWith
-------
by jiangshan (@jiangshanmeta) #中等 #template-literal
### 题目
实现`EndsWith<T, U>`,接收两个string类型参数,然后判断`T`是否以`U`结尾,根据结果返回`true`或`false`
例如:
```typescript
type a = EndsWith<'abc', 'bc'> // expected to be true
type b = EndsWith<'abc', 'abc'> // expected to be true
type c = EndsWith<'abc', 'd'> // expected to be false
```
> 在 Github 上查看:https://tsch.js.org/2693/zh-CN
*/
/* _____________ 你的代码 _____________ */
type EndsWith<T extends string, U extends string> =
T extends `${infer Q}${infer S}` ?
U extends `${Q}${infer N}` ?
T extends U ? true : false : EndsWith<S,U>
: false;
type test = EndsWith<'abc', 'bc'>
/* _____________ 测试用例 _____________ */
import type { Equal, Expect } from '@type-challenges/utils'
type cases = [
Expect<Equal<EndsWith<'abc', 'bc'>, true>>,
Expect<Equal<EndsWith<'abc', 'abc'>, true>>,
Expect<Equal<EndsWith<'abc', 'd'>, false>>,
]
/* _____________ 下一步 _____________ */
/*
> 分享你的解答:https://tsch.js.org/2693/answer/zh-CN
> 查看解答:https://tsch.js.org/2693/solutions
> 更多题目:https://tsch.js.org/zh-CN
*/
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。