Trim
提出詳細
type BlankChar = ' ' | '\n' | '\t' type TrimLeft<S extends String> = S extends `${BlankChar}${infer Rest}` ? TrimLeft<Rest> : S; type TrimRight<S extends String> = S extends `${infer Rest}${BlankChar}` ? TrimRight<Rest> : S; type Trim<S extends string> = TrimRight<TrimLeft<S>>
提出日時 | 2023-08-10 09:48:07 |
---|---|
問題 | Trim |
ユーザー | tekihei2317 |
ステータス | Accepted |
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<Trim<'str'>, 'str'>>, Expect<Equal<Trim<' str'>, 'str'>>, Expect<Equal<Trim<' str'>, 'str'>>, Expect<Equal<Trim<'str '>, 'str'>>, Expect<Equal<Trim<' str '>, 'str'>>, Expect<Equal<Trim<' \n\t foo bar \t'>, 'foo bar'>>, Expect<Equal<Trim<''>, ''>>, Expect<Equal<Trim<' \n\t '>, ''>>, ]