1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
var addStrings = function(num1, num2) { let [trav1, trav2, step, result] = [num1.length - 1, num2.length - 1, 0, ''];
while (trav1 >= 0 || trav2 >= 0) { const [v1, v2] = [ num1[trav1] ? Number(num1[trav1]) : 0, num2[trav2] ? Number(num2[trav2]) : 0, ]; const total = v1 + v2 + step; const temp = total % 10; result = temp + result; step = ~~(total / 10);
trav1--; trav2--; }
step && (result = step + result);
return result; };
|