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.
function translate(str) {
var RegEx = /[aeiouAEIOU]/;
var latinTranslation ="";
var vowelIndex ="";
if (str[0].match(RegEx)) {
latinTranslation = str + "way";
} else {
// Find how many consonants before the first vowel.
vowelIndex = str.indexOf(str.match(RegEx)[0]);
console.log(vowelIndex); // vowel is at index[1]
// Take the string from the first vowel to the last char
// then add the consonants that were previously omitted and add the ending.
latinTranslation = str.substr(vowelIndex) + str.substr(0, vowelIndex) + 'ay';
}
return latinTranslation;
}
translate("consonant");
translate("algorithm");