Skip to content

Instantly share code, notes, and snippets.

@soarez
Created Oct 8, 2012
Embed
What would you like to do?
Jumbler
function randomizeLetters(string) {
var letters = string.split('');
var result = '';
while(letters.length)
result += letters.splice(Math.floor(Math.random() * letters.length), 1)[0];
return result;
}
function jumbleWord(word) {
if (word.length < 3)
return word;
var first = word[0];
var last = word[word.length-1];
return first + randomizeLetters(word.slice(1, word.length - 1)) + last;
}
function jumble(string) {
var jumbled = [];
string.split(' ').forEach(function (w) { jumbled.push(jumbleWord(w)); });
return jumbled.join(' ');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment