Skip to content

Instantly share code, notes, and snippets.

@JCloudYu
Created August 12, 2018 16:44
Show Gist options
  • Save JCloudYu/bcf7d1aad606a635642ae83861e8f5c2 to your computer and use it in GitHub Desktop.
Save JCloudYu/bcf7d1aad606a635642ae83861e8f5c2 to your computer and use it in GitHub Desktop.
String.prototype.shuffle = function(){
var a = this.split(""),
n = a.length;
for( var i = n - 1; i > 0; i-- ){
var j = Math.floor(Math.random() * (i + 1));
var tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
return a.join("");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment