使用javascript 不使用 "+"方式实现两个二进制数组相加
例如:a = [1, 0, 1, 0], b = [1, 0, 1]
输出:[1, 1, 1, 1]
解析:
function plus (A, B) { let Btimp; let res = []; if (B.length > A.length) { Btimp = B B = A A = Btimp } let c = 0; while(A.length) { let a = A.pop(), b = B.pop() let s = a ^ b ^ c res.unshift(s) // Method 1 // c = a && b || b && c || a && c // Method 2 c = a && b || (a ^ b) && c } if (c) { res.unshift(c) } return res; }