-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfunction.ts
95 lines (81 loc) · 2.36 KB
/
function.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
var matchesAnyLetter = function(letter: string, mystring: string): boolean {
for (var z = 0; z < mystring.length; z++) {
var currentPosition = mystring[z];
if (letter === currentPosition) {
return true;
}
}
return false;
};
var isVowel = function(letter: string): boolean {
if ("aAiouEuIoeOiUa".indexOf(letter) !== -1) {
return true;
} else {
return false;
}
};
var makePigLatinWord = function(word: string): string {
var finalResult = "";
var cubbyOne = "";
var cubbyTwo = "";
var ending = "ay";
var cubbyFour = "";
if (word[0] === word[0].toUpperCase()) {
var wasCapitalized = true;
} else {
wasCapitalized = false;
}
for (var y = 0; y < word.length; y++) {
var currentLetter = word[y];
var previousLetter = word[y - 1];
if (currentLetter === "'") {
cubbyFour = currentLetter;
} else if (previousLetter === "'") {
cubbyFour = cubbyFour + currentLetter;
} else if (cubbyTwo !== "") {
finalResult = finalResult + currentLetter;
} else if (isVowel(currentLetter)) {
cubbyTwo = cubbyTwo + currentLetter;
} else {
cubbyOne = cubbyOne + currentLetter;
}
}
if (cubbyOne === "") {
ending = "y" + ending;
}
var pigLatinWord = cubbyTwo + finalResult + cubbyOne + ending + cubbyFour;
if (wasCapitalized === true) {
pigLatinWord = pigLatinWord.toLowerCase();
pigLatinWord =
pigLatinWord[0].toUpperCase() +
pigLatinWord.substring(1, pigLatinWord.length);
}
return pigLatinWord;
};
var makePigLatinSentence = function(sentence: string): string {
var currentWord = "";
var finalSentence = "";
var cubbyThree = "";
for (var z = 0; z < sentence.length; z++) {
var currentPosition = sentence[z];
if (
currentPosition === "," ||
currentPosition === "." ||
currentPosition === ";"
) {
cubbyThree = currentPosition;
} else if (currentPosition !== " ") {
currentWord = currentWord + currentPosition;
}
if (currentPosition === " " || z === sentence.length - 1) {
var pigLatinWord = makePigLatinWord(currentWord);
finalSentence = finalSentence + pigLatinWord + cubbyThree + " ";
cubbyThree = "";
currentWord = "";
}
}
return finalSentence;
};
var name1 = "pneumonoultramicroscopicsilicovolcanoconiosis.";
var result = makePigLatinSentence(name1);
console.log(result);