Skip to content

Instantly share code, notes, and snippets.

@texzhichen
Created January 3, 2018 07:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save texzhichen/b856de7cac23cc4abf77a6481cbd868b to your computer and use it in GitHub Desktop.
Save texzhichen/b856de7cac23cc4abf77a6481cbd868b to your computer and use it in GitHub Desktop.
// Reverse a string, e.g., '321' -> '123'
s.split('').reverse().join('')
// Give a random number within a range [a,b)
Math.random() * (b - a) + a;
// XOR swap
x = x^y;
y = x^y;
x = x^y;
// Arithmetic swap
y = y-x;
x = y+x;
y = x-y;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment