Created
November 30, 2018 17:43
-
-
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
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
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