-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpig.ts
52 lines (34 loc) · 1.04 KB
/
pig.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var string = "malucky likes to play league";
var currentWord = "";
var finalSentence = "";
for (var z = 0; z < string.length; z++){
var currentPosition = string[z];
if (currentPosition !== " "){
currentWord = currentWord + currentPosition;
}
if (currentPosition === " " || z === (string.length - 1)){
var x = currentWord;
var finalResult = "";
var cubbyOne = "";
var cubbyTwo = "";
var ending = "ay";
var pigLatinWord = "";
for (var y = 0; y < x.length; y++){
var currentLetter = x[y];
if (cubbyTwo !== ""){
finalResult = finalResult + currentLetter;
} else if (currentLetter === "a" || currentLetter === "e" || currentLetter === "i" || currentLetter === "o" || currentLetter === "u"){
cubbyTwo = cubbyTwo + currentLetter;
} else {
cubbyOne = cubbyOne + currentLetter;
}
}
if (cubbyOne === ""){
ending = "y" + ending;
}
pigLatinWord = cubbyTwo + finalResult + cubbyOne + ending;
finalSentence = finalSentence + pigLatinWord + " ";
currentWord = "";
}
}
console.log(finalSentence)