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-10 08:08:31 +00:00
|
|
|
};
|
2021-03-03 02:13:24 +00:00
|
|
|
|
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]);
|
2021-03-03 02:13:24 +00:00
|
|
|
};
|
2021-05-17 23:42:57 +00:00
|
|
|
|
2021-05-12 09:38:10 +00:00
|
|
|
module.exports = pigLatin;
|