Length of String
提出詳細
type LengthOfString<S extends string, T extends string[] = []> = S extends `${infer First}${infer Rest}` ? LengthOfString<Rest, [...T, First]> : T['length']
提出日時 | 2023-09-11 01:32:13 |
---|---|
問題 | Length of String |
ユーザー | snaka |
ステータス | Accepted |
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<LengthOfString<''>, 0>>, Expect<Equal<LengthOfString<'kumiko'>, 6>>, Expect<Equal<LengthOfString<'reina'>, 5>>, Expect<Equal<LengthOfString<'Sound! Euphonium'>, 16>>, ]