Created
September 12, 2012 21:58
-
-
Save asalant/3710244 to your computer and use it in GitHub Desktop.
brandon piglatin
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
| function pigTranslate(phrase){ | |
| return phrase.split(" ").map(function(item){ | |
| return wordTranslate(item); | |
| }).join(" "); | |
| } | |
| function wordTranslate(word){ | |
| var firstLetter = word.substring(0,1); | |
| var restOfWord = word.substring(1); | |
| if(firstLetter.match(/[A-Z]/)){ | |
| firstLetter = firstLetter.toLowerCase(); | |
| restOfWord = restOfWord.substring(0,1).toUpperCase() + restOfWord.substring(1); | |
| } | |
| return restOfWord + firstLetter + "ay"; | |
| } | |
| console.log(pigTranslate("hello world")); | |
| console.log(pigTranslate("Hello World")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment