Skip to content

Instantly share code, notes, and snippets.

@fakenickels
Created April 26, 2014 16:53
Show Gist options
  • Save fakenickels/11325001 to your computer and use it in GitHub Desktop.
Save fakenickels/11325001 to your computer and use it in GitHub Desktop.
Swap macro with Sweet.js
macro swap {
rule { $x and $y } => {
var tmp = $x;
$x = $y;
$y = tmp
}
}
// Let's go!
var a = "a",
b = "b";
console.log(a, b); // => a b
// And here the magic happens :3
swap a and b;
console.log(a, b); // b a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment