Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Shuffle a Sting in JavaScript

var shuffled = str.split('').sort(function(){return 0.5-Math.random()}).join('');
Comment

javascript shuffle string

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("");
}
console.log("the quick brown fox jumps over the lazy dog".shuffle());
//-> "veolrm  hth  ke opynug tusbxq ocrad ofeizwj"

console.log("the quick brown fox jumps over the lazy dog".shuffle());
//-> "o dt hutpe u iqrxj  yaenbwoolhsvmkcger ozf "
Comment

PREVIOUS NEXT
Code Example
Javascript :: fibonacci javascript 
Javascript :: remove specific property from json object javascript 
Javascript :: export aab react native 
Javascript :: update node mac to specific version 
Javascript :: dynamically add script code to page 
Javascript :: javascript json decode 
Javascript :: proactive vs reactive 
Javascript :: dice roller javascript 
Javascript :: innertext vs textcontent 
Javascript :: javascript add days to date 
Javascript :: get cursor position in contenteditable div 
Javascript :: extract words from string js 
Javascript :: vue on click router push not working 
Javascript :: how to modify external json file javascript 
Javascript :: How to get tailwindcss intellisense to work with react files 
Javascript :: install react native gifted charts 
Javascript :: prop-types instalation 
Javascript :: alert with sound javascript 
Javascript :: settimeout in a for loop javascript 
Javascript :: check palindrome javascript 
Javascript :: fetch api cors 
Javascript :: javascript get all classes 
Javascript :: loopback upsert 
Javascript :: javascript write text 
Javascript :: how to submit form using ajax 
Javascript :: eslintrc ignore rule 
Javascript :: internal/modules/cjs/loader.js:1122 
Javascript :: js how to print 
Javascript :: jsx foreach 
Javascript :: node js send fcm 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =