Created
July 18, 2022 07:22
-
-
Save lsongdev/2f1a069b381ed5185b46a193ba1252f3 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
const add = (a, b) => { | |
a = a.split('').reverse(); | |
b = b.split('').reverse(); | |
let a1, b1, c, d = 0, e, i = 0; | |
do { | |
a1 = +a[i] || 0; | |
b1 = +b[i] || 0; | |
c = a1 + b1 + d; | |
d = c / 10 | 0; | |
e = c % 10; | |
a[i] = e; | |
i++; | |
} while(d); | |
return a.reverse().join(''); | |
} | |
const a = '155'; | |
const b = '58'; | |
console.log(add(a, b)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment