Skip to content

Instantly share code, notes, and snippets.

@stephencweiss
Created November 30, 2018 17:43
Show Gist options
  • Save stephencweiss/ae9d910ee024b65ed0e7b10ae90feb60 to your computer and use it in GitHub Desktop.
Save stephencweiss/ae9d910ee024b65ed0e7b10ae90feb60 to your computer and use it in GitHub Desktop.
A bitwise swap function in Javascript - performing in place swap and constant space
var bitwiseSwap = (x,y) => {
if (x === y) {
return;
} else {
x = x ^ y;
y = x ^ y;
x = x ^ y;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment