Created
June 3, 2018 21:51
-
-
Save bockoblur/c134c3019a45a8f0559025d8edbc6e80 to your computer and use it in GitHub Desktop.
Shuffle letters in input string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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