let len = Math.max(a.length - 1, b.length - 1); let lens = 0; let str = []; let n = 0; while (lens <= len || n == 1) { let aval = parseInt(a[a.length - 1 - lens]) || 0; let bval = parseInt(b[b.length - 1 - lens]) || 0; let sum = aval + bval + n; if (sum > 1) { n = 1; sum %= 2; } else { n = 0; } str.unshift(sum); lens++; } return str.join(""); };