Skip to content

Instantly share code, notes, and snippets.

@jzelenkov
Created March 18, 2015 23:28
Show Gist options
  • Save jzelenkov/f93f1dc5fb9e03358d8e to your computer and use it in GitHub Desktop.
Save jzelenkov/f93f1dc5fb9e03358d8e to your computer and use it in GitHub Desktop.
Array.prototype.shuffle = function() {
var tmp = this.slice(0);
var res = [];
var pos;
for (var i = 0; i < this.length; i++) {
pos = Math.floor(Math.random() * tmp.length);
res.push(tmp.splice(pos, 1));
}
return "[" + res.join(", ") + "]";
}
@jzelenkov
Copy link
Author

  • 3x memory
  • O(n)

😞 😿

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment