Multiply
约 250 字小于 1 分钟
2026-02-11
题目
This challenge continues from 476 - Sum, it is recommended that you finish that one first, and modify your code based on it to start this challenge.
Implement a type Multiply<A, B> that multiplies two non-negative integers and returns their product as a string. Numbers can be specified as string, number, or bigint.
For example,
type T0 = Multiply<2, 3> // '6'
type T1 = Multiply<3, '5'> // '15'
type T2 = Multiply<'4', 10> // '40'
type T3 = Multiply<0, 16> // '0'
type T4 = Multiply<'13', '21'> // '273'
type T5 = Multiply<'43423', 321543n> // '13962361689'解题思路
待补充
答案
type Multiply<A extends string | number | bigint, B extends string | number | bigint> = string验证
import type { Equal, Expect } from '@type-challenges/utils'
type cases = [
Expect<Equal<Multiply<2, 3>, '6'>>,
Expect<Equal<Multiply<3, '5'>, '15'>>,
Expect<Equal<Multiply<'4', 10>, '40'>>,
Expect<Equal<Multiply<0, 16>, '0'>>,
Expect<Equal<Multiply<'13', '21'>, '273'>>,
Expect<Equal<Multiply<'43423', 321543n>, '13962361689'>>,
Expect<Equal<Multiply<9999, 1>, '9999'>>,
Expect<Equal<Multiply<4325234, '39532'>, '170985150488'>>,
Expect<Equal<Multiply<100_000n, '1'>, '100000'>>,
Expect<Equal<Multiply<259, 9125385>, '2363474715'>>,
Expect<Equal<Multiply<9, 99>, '891'>>,
Expect<Equal<Multiply<315, '100'>, '31500'>>,
Expect<Equal<Multiply<11n, 13n>, '143'>>,
Expect<Equal<Multiply<728, 0>, '0'>>,
Expect<Equal<Multiply<'0', 213>, '0'>>,
Expect<Equal<Multiply<0, '0'>, '0'>>,
]参考
无
