Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@fa7ad 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