/
euro.js
74 lines (65 loc) · 1.86 KB
/
euro.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
71
72
73
74
function simple(txt) {
let mid = txt.replace(/ph/g, "f")
.replace(/th/g, "z")
.replace(/ou/g, "o")
.replace(/ea/g, "e")
.replace(/w/g, "v")
.replace(/Ph/g, "F")
.replace(/Th/g, "Z")
.replace(/Ou/g, "O")
.replace(/Ea/g, "E")
.replace(/W/g, "V")
if (mid.endsWith("ed")) {
let o = mid.slice(0, mid.length - 2)
return (o + "d");
};
return mid;
};
function shorten(txt) {
if (txt.length <= 3) {
return txt;
};
if (txt.endsWith("e")) {
return txt.slice(0, txt.length - 1);
}
return txt;
}
// remove double
const takeWhile =
(fn, a) => a.length && fn(a[0]) ? [a[0], ...takeWhile(fn, a.slice(1))] : [];
function rmdouble(x) {
if (x.length < 2)
return x;
let mid = takeWhile((y) => { return y == x[0] }, x);
let rest = x.slice(mid.length, x.length);
return (mid[0] + rmdouble(rest));
}
// remove c
function ctosk(txt) {
if (txt.length < 2)
return txt;
var x = txt;
for (var i = 0; i < txt.length - 1; i++) {
if (x[i] == "c") {
if ("eiy".includes(x[i + 1])) {
x = x.substr(0, i - 1) + "s" + x.substr(i + 1, txt.length - 1);
} else {
x = x.substr(0, i - 1) + "k" + x.substr(i + 1, txt.length - 1);
}
} else if (x[i] == "C") {
if ("eiy".includes(x[i + 1])) {
x = x.substr(0, i - 1) + "S" + x.substr(i + 1, txt.length - 1);
} else {
x = x.substr(0, i - 1) + "K" + x.substr(i + 1, txt.length - 1);
}
}
}
return x;
}
function euro(txt) {
return simple(rmdouble(shorten(ctosk(txt))))
}
function convert() {
var text = document.getElementById("input-area").value.replace(/\n/g, '<br/>');
document.getElementById("output").innerHTML = euro(text);
}