In most languages, if you want to swap two variables, it’s something like:
var c = b
b = a
a = c
Yes, you can do fancy hacks with XOR if you like but it’s generally 3 lines of code for a single operation. Are there any languages that have swapping variables as a primitive in the language?
Lua, Python, Ruby and more support this notation:
And javascript sure needs no temporary variable either 😉
For more examples on how to swap variables (in 86 languages), see: http://rosettacode.org/wiki/Generic_swap