mirror of
https://github.com/10h30/odin-javascript-exercises.git
synced 2026-06-05 15:09:09 +09:00
piglatin
This commit is contained in:
+19
-5
@@ -1,9 +1,23 @@
|
|||||||
function translate() {
|
function translate(string) {
|
||||||
// body...
|
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(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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]);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
translate
|
translate
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user