Skip to content

Instantly share code, notes, and snippets.

@KevinTCoughlin
Last active November 9, 2015 17:21
Show Gist options
  • Select an option

  • Save KevinTCoughlin/2ee2a9c1b151e05cb08e to your computer and use it in GitHub Desktop.

Select an option

Save KevinTCoughlin/2ee2a9c1b151e05cb08e to your computer and use it in GitHub Desktop.
var input = "According to a research team at Cambridge University, it doesn't matter in what order the letters in a word are, \n"
+ "the only important thing is that the first and last letter be in the right place. \n"
+ "The rest can be a total mess and you can still read it without a problem.\n"
+ "This is because the human mind does not read every letter by itself, but the word as a whole. \n"
+ "Such a condition is appropriately called Typoglycemia.";
function typoglycemia(phrase) {
return phrase.split(' ').map(scramble).join(' ');
}
function scramble(word) {
var charArr = word.split('');
var innerWord = _.shuffle(charArr.slice(1, charArr.length - 1));
innerWord.unshift(charArr[0]);
if (charArr.length > 1) {
innerWord.push(charArr[charArr.length - 1]);
}
return innerWord.join('');
}
var result = typoglycemia(input);
console.log(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment