Skip to content

Instantly share code, notes, and snippets.

@alexpilugin
Created August 29, 2019 22:45
Show Gist options
  • Save alexpilugin/ae43d9677dd42fcbb31494ba933f8065 to your computer and use it in GitHub Desktop.
Save alexpilugin/ae43d9677dd42fcbb31494ba933f8065 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("");
}
function shuffle(str) {
var a = str.split("");
var 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