Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function sum(a, b) {
- const arrA = a.split('').reverse();
- const arrB = b.split('').reverse();
- let longer = [];
- let theOther = [];
- if (arrA.length > arrB.length) {
- longer = [...arrA];
- theOther = [...arrB];
- } else {
- longer = [...arrB];
- theOther = [...arrA];
- }
- const result = [];
- for (let i = longer.length - 1; i >= 0; i--) {
- if (!theOther[i]) {
- result.push(Number(longer[i]));
- continue;
- }
- result.push(Number(longer[i]) + Number(theOther[i]));
- }
- return result.join('');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement