shuffle a sting in javascript

Solutions on MaxInterview for shuffle a sting in javascript by the best coders in the world

showing results for - "shuffle a sting in javascript"
Matthew
19 Nov 2016
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
Eline
24 Apr 2016
1var shuffled = str.split('').sort(function(){return 0.5-Math.random()}).join('');
2
queries leading to this page
how to shuffle array of strings in javascriptstring shuffle js1528 shuffle string javascriptjs sort random stringrandomly rearrange string in jsscramble string javascriptshuffle string jsstring letters shuffle jshow to shuffle a js stringhow to shuffle a string in javascripthow to convert shuffle string in javascriptshuffle a sting in javascriptjs shuffle string lettersshuffle array of strings javascriptjavascript every shuffle of stringhow to shuffle characters in a string in jsstring shuffle 2funshuffle javascripthow to get back a string from a shuffle string in node jshow to shuffle a substring in javascriptrandomy shuffle an array of stirngs jsshuffle words in string javascriptstring shuffle javascripthow to shuffle strings in javascriptjs shuffle stringjavascript take a string and shufflt its contentstr shuffle jsjs shuffle string arrayshuffle array of stringsjavascriptscramble string jsjs randomize stringrandom order string jsshuffle string javascriptrandom mix string javascriptshuffle an array of strings in javascriptswitch string randomly javascriptjavascript shuffle array of stringsshuffle a string in javascriptshuffle string javascript charatstr shuffle in javascriptjavascript shuffle string arrayshuffle array of strings jshow to shuffle the alphabet in jshow to get back a string from a shuffle string in nodejsjs shuffle string onlinehow to break into pieces shuffle string in javascript shuffle an array of strings in js javascript scramble stringjs function that shuffles a stringshuffle a single string in javascriptshuffle characters in a string javascriptjs string shuffleshuffle substrings in javascriptmix string randomly jshow ot shuffle characters in string jshow to scramble a string in javascriptshuffle a string javascripthow to shuffle string characters in jsjavascript random shuffle stringshuffle string node jsshuffle array of string javascriptrandom shuffle characters from a string in javascriptshuffle string in jsjavascript string shufflejavascript shuffle stringhow to shuffle string in javascriptrandomize order of string jssort string randomly javascriptshuffle a sting in javascript