Skip to content

Commit

Permalink
feat: trim-right
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouzhenpan committed Jul 26, 2024
1 parent 550a218 commit 0bc6c47
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/04803-medium-trim-right.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// ============= Test Cases =============
import type { Equal, Expect } from './test-utils'

type cases = [
Expect<Equal<TrimRight<'str'>, 'str'>>,
Expect<Equal<TrimRight<'str '>, 'str'>>,
Expect<Equal<TrimRight<'str '>, 'str'>>,
Expect<Equal<TrimRight<' str '>, ' str'>>,
Expect<Equal<TrimRight<' foo bar \n\t '>, ' foo bar'>>,
Expect<Equal<TrimRight<''>, ''>>,
Expect<Equal<TrimRight<'\n\t '>, ''>>
]

type Space = ' ' | '\n' | '\t'
// ============= Your Code Here =============
type TrimRight<S extends string> = S extends `${infer F}${Space}`
? TrimRight<F>
: S

0 comments on commit 0bc6c47

Please sign in to comment.