Created
March 27, 2016 10:27
-
-
Save samkahchiin/4f88aee5628485f48f76 to your computer and use it in GitHub Desktop.
freecodecamp : Pig Latin
This file contains 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 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