Last active
November 9, 2015 17:21
-
-
Save KevinTCoughlin/2ee2a9c1b151e05cb08e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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