Skip to content

Instantly share code, notes, and snippets.

@guxuerui
Created July 2, 2020 06:38
Show Gist options
  • Save guxuerui/6e397bb6fe9fb25b7f9a01e0f4159ef4 to your computer and use it in GitHub Desktop.
Save guxuerui/6e397bb6fe9fb25b7f9a01e0f4159ef4 to your computer and use it in GitHub Desktop.
js两数求和
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