1String.prototype.shuffle = function () {
2 var a = this.split(""),
3 n = a.length;
4
5 for(var i = n - 1; i > 0; i--) {
6 var j = Math.floor(Math.random() * (i + 1));
7 var tmp = a[i];
8 a[i] = a[j];
9 a[j] = tmp;
10 }
11 return a.join("");
12}
13console.log("the quick brown fox jumps over the lazy dog".shuffle());
14//-> "veolrm hth ke opynug tusbxq ocrad ofeizwj"
15
16console.log("the quick brown fox jumps over the lazy dog".shuffle());
17//-> "o dt hutpe u iqrxj yaenbwoolhsvmkcger ozf "
18
1var shuffled = str.split('').sort(function(){return 0.5-Math.random()}).join('');
2