2017-12-15 10:52:22 -08:00
|
|
|
function translate(string) {
|
|
|
|
return string
|
|
|
|
.split(" ")
|
|
|
|
.map(word => {
|
|
|
|
const index = firstVowelIndex(word);
|
|
|
|
const beginning = word.slice(0, index);
|
|
|
|
const ending = word.slice(index);
|
|
|
|
return `${ending}${beginning}ay`;
|
|
|
|
})
|
|
|
|
.join(" ");
|
2017-09-20 16:04:46 -07:00
|
|
|
}
|
|
|
|
|
2017-12-15 10:52:22 -08:00
|
|
|
function firstVowelIndex(string) {
|
|
|
|
const vowels = string.match(/[aeiou]/g);
|
|
|
|
if (vowels[0] == "u" && string[string.indexOf(vowels[0]) - 1] == "q") {
|
|
|
|
return string.indexOf(vowels[1]);
|
|
|
|
}
|
|
|
|
return string.indexOf(vowels[0]);
|
2017-09-20 16:04:46 -07:00
|
|
|
}
|
|
|
|
|
2017-12-15 10:52:22 -08:00
|
|
|
module.exports = {
|
|
|
|
translate
|
|
|
|
};
|