Created
August 10, 2015 21:34
-
-
Save alexandrebvd/2c1a7ce746baca719bd2 to your computer and use it in GitHub Desktop.
23.Bonfire: 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) { | |
var vowel = ['a', 'e', 'i', 'o', 'u']; | |
var stop = false; | |
var numberOfConsonant = 0; | |
str = str.split(''); | |
length = str.length; | |
strNew = str; | |
for (var i = 0; i < length; i++) { | |
if (vowel.indexOf(str[0]) !== -1 && !stop){ | |
strNew.push('way'); | |
stop = true; | |
} | |
else if (vowel.indexOf(str[i]) === -1 && !stop) { | |
strNew.push(str[i]); | |
numberOfConsonant++; | |
console.log(numberOfConsonant) | |
} | |
else { | |
stop = true; | |
} | |
} | |
if (numberOfConsonant > 0) { | |
strNew.push('ay'); | |
} | |
console.log(strNew); | |
strNew = strNew.join('').substr(numberOfConsonant); | |
console.log(strNew); | |
return strNew; | |
} | |
translate("glove"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment