Arbitrary-precision arithmetic adds and multiplies numbers that are too large to fit in a machine word by operating on their decimal digits directly, exactly the way you would on paper. JavaScript's number type is an IEEE-754 double that stays exact only up to Number.MAX_SAFE_INTEGER (that is 2^53 - 1, or 9007199254740991); past that, calling Number('12345678901234567890') silently rounds the value before you have done any math. You will implement add and multiply for non-negative integers handed to you as decimal strings of any length, packaged on one object bigintStringArithmetic = { add, multiply } — no BigInt, no Number on the whole value, no libraries.
bigintStringArithmetic.add(a, b) // (decimal string, decimal string) -> decimal string
bigintStringArithmetic.multiply(a, b) // (decimal string, decimal string) -> decimal string
bigintStringArithmetic.add('2', '3'); // '5'
bigintStringArithmetic.add('99', '1'); // '100'
bigintStringArithmetic.add('12345678901234567890', '98765432109876543210');
// '111111111011111111100' — a plain Number(a) + Number(b) drops the low digits
bigintStringArithmetic.multiply('123', '456'); // '56088'
bigintStringArithmetic.multiply('99', '99'); // '9801'
bigintStringArithmetic.multiply('12345678901234567890', '0'); // '0'
'0' itself, which is exactly one zero. You do not need to validate them.BigInt, convert the whole string with Number or parseInt, or reach for a big-number library. Converting a single digit character is fine; converting the whole value is the bug.multiply('0', '5') returns '0', not '000', and add('1', '9') returns '10'.Unlock the solution & editor
Runnable editor + tests
Solve in the browser with instant Jest feedback.
Detailed solutions
Walkthroughs, edge cases, and complexity notes.
Multi-framework variants
React, Vue, Vanilla, Angular — same question, different stacks.