Created
December 16, 2019 09:21
-
-
Save fa7ad/6e0ee3ff693b5b93db80b3ed606e52f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function add(a, b) { | |
let c = 0; | |
let n = a.length > b.length ? a : b | |
let m = n === a ? b.padStart(a.length, 0) : a.padStart(b.length, 0) | |
let r = [] | |
for(let i = n.length - 1;i >= 0; i--){ | |
let s = c > 0 ? c-- : 0; | |
s += +n[i] + +m[i] | |
if (s > 9) c++ | |
r.unshift((s%10)+"") | |
} | |
if (c > 0) | |
r.unshift(c) | |
return r.join('') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add arbitrary length string integers. Naive memory bound solution