Skip to content

Instantly share code, notes, and snippets.

@ronaldoarg
Created March 3, 2018 23:29
Show Gist options
  • Save ronaldoarg/d30abe3c99593b22a7f937ac59f68a1e to your computer and use it in GitHub Desktop.
Save ronaldoarg/d30abe3c99593b22a7f937ac59f68a1e to your computer and use it in GitHub Desktop.
My solution for FreeCodeCamp | Pig Latin exercise.
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