Capitalize Words
提出詳細
type Char = "q" | "w" | "e" | "r" | "t" | "y" | "u" | "i" | "o" | "p" | "a" | "s" | "d" | "f" | "g" | "h" | "j" | "k" | "l" | "z" | "x" | "c" | "v" | "b" | "n" | "m" type CapitalizeWords<T extends string, Acc extends string = "", Res extends string = ""> = T extends `${infer L}${infer R}` ? L extends Char ? CapitalizeWords<R, `${Acc}${L}`, Res> : CapitalizeWords<R, "", `${Res}${Capitalize<Acc>}${L}`> : `${Res}${Capitalize<Acc>}`
提出日時 | 2024-09-12 15:14:39 |
---|---|
問題 | Capitalize Words |
ユーザー | ookkoouu |
ステータス | Accepted |
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<CapitalizeWords<'foobar'>, 'Foobar'>>, Expect<Equal<CapitalizeWords<'FOOBAR'>, 'FOOBAR'>>, Expect<Equal<CapitalizeWords<'foo bar'>, 'Foo Bar'>>, Expect<Equal<CapitalizeWords<'foo bar hello world'>, 'Foo Bar Hello World'>>, Expect<Equal<CapitalizeWords<'foo bar.hello,world'>, 'Foo Bar.Hello,World'>>, Expect<Equal<CapitalizeWords<''>, ''>>, ]