-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathperiod.ts
54 lines (39 loc) · 1.34 KB
/
period.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
53
54
var string = "This is Tyler's Sentence.";
var currentWord = "";
var finalSentence = "";
var cubbyThree = "";
for (var z = 0; z < string.length; z++){
var currentPosition = string[z];
if (currentPosition === "," || currentPosition === "." || currentPosition === ";"){
cubbyThree = currentPosition;
} else 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" || 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 + cubbyThree + " ";
cubbyThree = "";
currentWord = "";
}
}
console.log(finalSentence)