8000 piglatin · nima-m-git/javascript-exercises@14cc7d4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 14cc7d4

Browse files
committed
piglatin
1 parent 956727d commit 14cc7d4

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

pig_latin/pigLatin.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
1-
function translate() {
2-
// body...
1+
function translate(string) {
2+
return string
3+
.split(" ")
4+
.map(word => {
5+
const index = firstVowelIndex(word);
6+
const beginning = word.slice(0, index);
7+
const ending = word.slice(index);
8+
return `${ending}${beginning}ay`;
9+
})
10+
.join(" ");
311
}
412

5-
6-
module.exports = {
7-
translate
13+
function firstVowelIndex(string) {
14+
const vowels = string.match(/[aeiou]/g);
15+
if (vowels[0] == "u" && string[string.indexOf(vowels[0]) - 1] == "q") {
16+
return string.indexOf(vowels[1]);
17+
}
18+
return string.indexOf(vowels[0]);
819
}
920

21+
module.exports = {
22+
translate
23+
};

0 commit comments

Comments
 (0)
0