Last active
June 18, 2018 13:12
-
-
Save e-mihaylin/ab1ec3121272a5c9a3c9f58a4fb5e872 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 SumBigNumbers (a, b) { | |
var res = '', c = 0; | |
a = a.split(''); | |
b = b.split(''); | |
while (a.length || b.length || c) { | |
c += ~~a.pop() + ~~b.pop(); | |
res = c % 10 + res; | |
c = c > 9; | |
} | |
return res; | |
} | |
// const SumBigNumbers = (a, b) => { | |
// a = a.replace(/^0+/, '').split``.reverse``; | |
// b = b.replace(/^0+/, '').split``.reverse``; | |
// const max = Math.max(a.length, b.length); | |
// let result = []; | |
// for (let memo = 0, i = 0; i < max; i++) { | |
// let res = parseInt(a[i] || 0) + parseInt(b[i] || 0) + memo; | |
// result[i] = res % 10; | |
// memo = (res - result[i]) / 10; | |
// if (memo) result.push(memo); | |
// } | |
// return result.reverse().join``; | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment