Created
March 3, 2018 23:29
-
-
Save ronaldoarg/d30abe3c99593b22a7f937ac59f68a1e to your computer and use it in GitHub Desktop.
My solution for FreeCodeCamp | Pig Latin exercise.
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 translatePigLatin(str) { | |
var prefix = ''; | |
str.split('').some(function(char) { | |
if (char.isVowel()) | |
return true; | |
else | |
prefix += char; | |
}); | |
return str.substr(prefix.length, str.length) + (prefix || 'w') + 'ay'; | |
} | |
function isVowel() { | |
var self = this; | |
var vowels = ['a', 'e', 'i', 'o', 'u']; | |
return vowels.some(function(vowel) { | |
return self == vowel; | |
}); | |
} | |
Object.prototype.isVowel = isVowel; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment