Trim Right
提出詳細
type WhiteSpace = " " | "\n" | "\t" type Reverse<S extends string> = S extends `${infer S1}${infer S2}` ? `${Reverse<S2>}${S1}` : "" type TrimLeft<S extends string> = S extends `${WhiteSpace}${infer S2}` ? TrimLeft<S2> : S type TrimRight<S extends string> = Reverse<TrimLeft<Reverse<S>>>
提出日時 | 2023-09-18 07:32:48 |
---|---|
問題 | Trim Right |
ユーザー | sankantsu |
ステータス | Accepted |
import type { Equal, Expect } from '@type-challenges/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 '>, ''>>, ]