Skip to content

Instantly share code, notes, and snippets.

@asalant
Created September 12, 2012 21:58
Show Gist options
  • Select an option

  • Save asalant/3710244 to your computer and use it in GitHub Desktop.

Select an option

Save asalant/3710244 to your computer and use it in GitHub Desktop.
brandon piglatin
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