Skip to content

Commit f89eae9

Browse files
authored
Merge pull request #2 from tejas-2232/master
Updates from original repo
2 parents 44e1b5f + 09bcf24 commit f89eae9

File tree

6 files changed

+382
-15
lines changed

6 files changed

+382
-15
lines changed

Pig_latin_6/pig_latin.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
function pigLatin_declarative(str) {
2+
return str
3+
.replace(/^([aeiouy])(._)/, '$1$2way')
4+
.replace(/^(_[_^aeiouy]+)(._)/, '$2$1ay')
5+
}
6+
7+
function pigLatin_imperative(str) {
8+
// Convert string to lowercase
9+
str = str.toLowerCase()
10+
// Initialize array of vowels
11+
const vowels = ["a", "e", "i", "o", "u"];
12+
// Initialize vowel index to 0
13+
let vowelIndex = 0;
14+
15+
if (vowels.includes(str[0])) {
16+
// If first letter is a vowel
17+
return str + "way";
18+
} else {
19+
// If the first letter isn't a vowel i.e is a consonant
20+
for (let char of str) {
21+
// Loop through until the first vowel is found
22+
if (vowels.includes(char)) {
23+
// Store the index at which the first vowel exists
24+
vowelIndex = str.indexOf(char);
25+
break;
26+
}
27+
}
28+
// Compose final string
29+
return str.slice(vowelIndex) + str.slice(0, vowelIndex) + "ay";
30+
}
31+
}

0 commit comments

Comments
 (0)