Skip to content

Instantly share code, notes, and snippets.

@bockoblur
Created June 3, 2018 21:51
Show Gist options
  • Save bockoblur/c134c3019a45a8f0559025d8edbc6e80 to your computer and use it in GitHub Desktop.
Save bockoblur/c134c3019a45a8f0559025d8edbc6e80 to your computer and use it in GitHub Desktop.
Shuffle letters in input string
//range: (0..x-1)
function rnd(x){
return Math.floor(Math.random()*x);
}
function shuffleLetters(s){
var res="";
var a=s.split("");
while (a.length>0)
res+=a.splice(rnd(a.length),1)[0];
return res;
}
/* usage
let word="supercalifragilisticexpialidocious";
console.log(shuffleLetters(word));
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment