-
Notifications
You must be signed in to change notification settings - Fork 0
/
logic.js
70 lines (61 loc) · 2.02 KB
/
logic.js
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
const isVowel = function (character) {
return character === "a" || character === "i" || character === "u" || character === "e" || character === "o";
}
const gConverter = function (requestedText) {
let newText = "";
requestedTextSplit = requestedText.split(" ");
for (let root = 0; root < requestedTextSplit.length; root++) {
const element = requestedTextSplit[root];
for (var i = 0; i < element.length; i++) {
newText += element.charAt(i);
if (isVowel(element.charAt(i).toLowerCase())) {
newText += "g";
newText += element.charAt(i);
continue;
}
if ((i + 2) <= element.length) {
if (isVowel(element.charAt(i + 2))) {
continue;
}
const endWord = element.charAt(i) + element.charAt(i + 1);
switch (endWord) {
case 'ng':
continue;
default:
break;
}
}
if ((i + 1) <= element.length) {
if (isVowel(element.charAt(i + 1))) {
continue;
}
}
if ((i + 3) <= element.length) {
const endWord = element.charAt(i + 1) + element.charAt(i + 2) + element.charAt(i + 3);
switch (endWord) {
case 'nya':
continue;
case 'man':
continue;
case 'kan':
continue;
case 'wan':
continue;
default:
break;
}
}
if (i !== element.length - 1) {
newText += "ege";
}
}
if (root === requestedTextSplit.length - 1) {
return newText;
}
newText += " "
}
return newText;
}
module.exports = {
gConverter,
}