Created
February 8, 2016 13:08
-
-
Save fupslot/909010b30d19b942aa03 to your computer and use it in GitHub Desktop.
swap variable values (not temporary variable)
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
// variables | |
var a = 10; | |
var b = 99; | |
// a^=b, b^=a, a^=b - swap variables using XOR operation, | |
// details: http://en.wikipedia.org/wiki/XOR_swap_algorithm | |
a^=b, b^=a, a^=b; | |
console.log('a', a); | |
console.log('b', b); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment