Add to Array-Form of Number

ARRAY
MATH

Problem

Given an integer num in array-form (an array of its digits) and an integer k, the function returns the array-form of the result of adding num and k.

The array-form represents the digits of the number from left to right.

The function efficiently handles carrying over digits during addition.

Examples

add([3,4,5,6], 234) // [3,6,9,0] // Why? 3456 + 234 = 3690 add([1,9,9], 2) // [2,0,1] // Why? 199 + 2 = 201 add([9,9,9], 2) // [1,0,0,1] // Why? 999 + 2 = 1001
Loading...