Skip to content

Instantly share code, notes, and snippets.

@xingoxu
Last active March 24, 2019 05:50
Show Gist options
  • Select an option

  • Save xingoxu/c31cf15e5daad2e170f096847fe11ff3 to your computer and use it in GitHub Desktop.

Select an option

Save xingoxu/c31cf15e5daad2e170f096847fe11ff3 to your computer and use it in GitHub Desktop.
use CLRS RANDOMIZE-IN-PLACE
Array.prototype.shuffle = function shuffle() {
for (let i = 0; i < this.length; i++){
let randomI = Math.floor(Math.random() * (this.length - i)) + i;
let temp = this[i];
this[i] = this[randomI];
this[randomI] = temp;
}
return this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment