mirror of
https://github.com/type-challenges/type-challenges.git
synced 2026-01-25 14:47:17 +00:00
Co-authored-by: Anthony Fu <11247099+antfu@users.noreply.github.com>
This commit is contained in:
parent
69a21fdad5
commit
72d338afb9
7
questions/116-medium-replace/README.md
Normal file
7
questions/116-medium-replace/README.md
Normal file
@ -0,0 +1,7 @@
|
||||
Implement `Replace<S, From, To>` which replace the string `From` with `To` once in the given string `S`
|
||||
|
||||
For example
|
||||
|
||||
```ts
|
||||
type replaced = Replace<'types are fun!', 'fun', 'awesome'> // expected to be 'types are awesome!'
|
||||
```
|
||||
9
questions/116-medium-replace/info.yml
Normal file
9
questions/116-medium-replace/info.yml
Normal file
@ -0,0 +1,9 @@
|
||||
difficulty: medium
|
||||
title: Replace
|
||||
tags: template-string
|
||||
tsconfig:
|
||||
ts: 4.1.0-pr-40336-88
|
||||
author:
|
||||
github: antfu
|
||||
name: Anthony Fu
|
||||
|
||||
1
questions/116-medium-replace/template.ts
Normal file
1
questions/116-medium-replace/template.ts
Normal file
@ -0,0 +1 @@
|
||||
type Replace<S extends string, From extends string, To extends string> = any
|
||||
8
questions/116-medium-replace/test-cases.ts
Normal file
8
questions/116-medium-replace/test-cases.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { Equal, Expect } from '@type-challenges/utils'
|
||||
|
||||
type cases = [
|
||||
Expect<Equal<Replace<'foobar', 'bar', 'foo'>, 'foofoo'>>,
|
||||
Expect<Equal<Replace<'foobarbar', 'bar', 'foo'>, 'foofoobar'>>,
|
||||
Expect<Equal<Replace<'foobarbar', '', 'foo'>, 'foobarbar'>>,
|
||||
Expect<Equal<Replace<'', '', ''>, ''>>,
|
||||
]
|
||||
Loading…
x
Reference in New Issue
Block a user