8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 956727d commit 14cc7d4Copy full SHA for 14cc7d4
pig_latin/pigLatin.js
@@ -1,9 +1,23 @@
1
-function translate() {
2
- // body...
+function translate(string) {
+ 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(" ");
11
}
12
-
-module.exports = {
- 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]);
19
20
21
+module.exports = {
22
+ translate
23
+};
0 commit comments