Skip to content

Instantly share code, notes, and snippets.

@samkahchiin
Created March 27, 2016 10:27
Show Gist options
  • Save samkahchiin/4f88aee5628485f48f76 to your computer and use it in GitHub Desktop.
Save samkahchiin/4f88aee5628485f48f76 to your computer and use it in GitHub Desktop.
freecodecamp : Pig Latin
function translate(str) {
if((/^[aeiou]$/i).test(str[0])){
str = str + "way";
}else{
if((/^[aeiou]$/i).test(str[1])){
str = str.slice(1) + str[0] + "ay";
}else{
str = str.slice(2) + str[0] + str[1] + "ay";
}
}
return str;
}
translate("algorithm");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment