Skip to content

Instantly share code, notes, and snippets.

@song940
Created July 18, 2022 07:22
Show Gist options
  • Save song940/2f1a069b381ed5185b46a193ba1252f3 to your computer and use it in GitHub Desktop.
Save song940/2f1a069b381ed5185b46a193ba1252f3 to your computer and use it in GitHub Desktop.
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