Binary to Decimal
提出詳細
type BinaryToDecimal<S extends string, Acc extends readonly unknown[]=[]> = S extends "" ? Acc["length"] : S extends `0${infer S2}` ? BinaryToDecimal<S2, [...Acc, ...Acc]> : S extends `1${infer S2}` ? BinaryToDecimal<S2, [...Acc, ...Acc, 0]> : never
提出日時 | 2023-09-19 05:14:54 |
---|---|
問題 | Binary to Decimal |
ユーザー | sankantsu |
ステータス | Accepted |
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<BinaryToDecimal<'10'>, 2>>, Expect<Equal<BinaryToDecimal<'0011'>, 3>>, Expect<Equal<BinaryToDecimal<'00000000'>, 0>>, Expect<Equal<BinaryToDecimal<'11111111'>, 255>>, Expect<Equal<BinaryToDecimal<'10101010'>, 170>>, ]