-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmnx.js
58 lines (56 loc) · 1.64 KB
/
mnx.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
module.exports = function() {
var s = this;
this.mWd = function(T) {
var L = T.length;
switch (L) {
case (1):
return T;
case (2):
return T.substring(1) + T.substring(0, 1);
case (3):
return T.substring(2) + T.substring(1, 2) + T.substring(0, 1)
case (4):
T = T.split('');
return T[0] + T[3] + T[2] + T[1];
default:
T = T.split('');
if (L % 2 == 0) {
var nT = T[T.length - 1]
var lC = T[0]
for (var i = 1; i != (T.length - 1); i += 2) {
nT += T[i + 1]
nT += T[i]
}
nT += lC;
return nT;
} else {
var nT = T[T.length - 1]
var lC = T[T.length - 2] + T[0]
for (var i = 1; i != (T.length - 2); i += 2) {
nT += T[i + 1]
nT += T[i]
}
nT += lC;
return nT;
}
}
}
this.mnx = function(S) {
S = S.split(' ')
if (S[S.length - 1] == '') {
S = S.slice(0, S.length - 1)
}
var OT = '';
S.forEach(function(w) {
var und = w
w = s.mWd(w)
if (S.indexOf(und) != (S.length - 1)) {
OT += w + ' ';
} else {
OT += w;
}
return;
})
return OT;
}
}