Created
July 2, 2020 06:38
-
-
Save guxuerui/6e397bb6fe9fb25b7f9a01e0f4159ef4 to your computer and use it in GitHub Desktop.
js两数求和
This file contains 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 sum = (a, b) => { | |
if (a == 0) return b; | |
if (b == 0) return a; | |
let newA = a ^ b; | |
let newB = (a & b) << 1; | |
return sum(newA, newB); | |
} | |
const a = 10, b = 5; | |
console.log(sum(a, b)); // 15 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment