2021-05-09 12:06:18 +00:00
|
|
|
const pigLatin = function(string) {
|
2021-04-30 10:12:52 +00:00
|
|
|
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(" ");
|
|
|
|
}
|
|
|
|
|
2021-05-09 12:06:18 +00:00
|
|
|
const firstVowelIndex = function(string) {
|
2021-04-30 10:12:52 +00:00
|
|
|
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]);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = pigLatin
|