Skip to content

Instantly share code, notes, and snippets.

@fa7ad
Created December 16, 2019 09:21
Show Gist options
  • Save fa7ad/6e0ee3ff693b5b93db80b3ed606e52f0 to your computer and use it in GitHub Desktop.
Save fa7ad/6e0ee3ff693b5b93db80b3ed606e52f0 to your computer and use it in GitHub Desktop.
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('')
}
@fa7ad
Copy link
Author

fa7ad commented Dec 16, 2019

Add arbitrary length string integers. Naive memory bound solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment