Skip to content

Instantly share code, notes, and snippets.

@rfprod
Last active April 22, 2017 16:00
Show Gist options
  • Save rfprod/295ccede30364dabd3cd to your computer and use it in GitHub Desktop.
Save rfprod/295ccede30364dabd3cd to your computer and use it in GitHub Desktop.
Pig Latin
function translate(str) {
var consonants = ["B", "C", "D", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "V", "X", "Z", "W", "Y"];
var vowels = ["A", "E", "I", "O", "U"];
var cnct = "";
for (var i=0;i<consonants.length;i++){
if (str[0] == consonants[i].toLowerCase()){
cnct = cnct.concat(str[0]);
str = str.slice(1,str.length);
}
}
if (cnct === ""){
for (var j=0;j<vowels.length;j++){
if (str[0] == vowels[j].toLowerCase()){
cnct = "w";
}
}
}
str = str.concat(cnct).concat("ay");
return str;
}
translate("algorithm");

Pig Latin

Translates the provided string to pig latin. Pig Latin takes the first consonant (or consonant cluster) of an English word, moves it to the end of the word and suffixes an "ay". If a word begins with a vowel it justs add "way" to the end.

A script by V.

License.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment