Created
February 28, 2016 11:55
-
-
Save sedera-tax/8680f669bc0fa0ec141a to your computer and use it in GitHub Desktop.
Translate 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 you just add "way" to the end.
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 translate(str) { | |
var length = str.length; | |
var tab = []; | |
for(var i=0; i<length; i++){ | |
var first = str.charAt(i); | |
//voyelle | |
if(first === "a" || first === "e" || first === "i" || first === "o" || first === "u" || first === "y"){ | |
if(i === 0){ | |
str = str + "way"; | |
} | |
else{ | |
str = str.substring(i) + tab.join("") + "ay"; | |
} | |
break; | |
} | |
//consonne | |
else{ | |
tab.push(first); | |
} | |
} | |
return str; | |
} | |
translate("consonant"); | |
translate("glove"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment