-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtype.js
More file actions
200 lines (169 loc) · 5.89 KB
/
type.js
File metadata and controls
200 lines (169 loc) · 5.89 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/////////////////////////////////////////////////////////////////////////////
//////// T Y P E C L A S S ( O B J E C T T E M P L A T E) /////////
/////////////////////////////////////////////////////////////////////////////
class Type {
constructor(_MBTI, isMBTI) {
var a = getFunctionsFromType(_MBTI, isMBTI);
this.dominantFunction = a[0];
this.auxillaryFunction = a[1];
this.mbti = isMBTI;
var f = getNumbersFromType(_MBTI, isMBTI);
this.firstFunction = f[0];
this.secondFunction = f[1];
}
// Returns an int[2] with first two functions
getSerialNumbers() {
var a = [0, 0];
a[0] = this.firstFunction;
a[1] = this.secondFunction;
return a;
}
// Return type as a string
toTypeCode() {
return getTypeFromFunctions(this.dominantFunction, this.auxillaryFunction, this.mbti);
}
}
////////////////////////////////////////////////////////////////////////////
// From type to first two functions
// Returns a string[2]
function getFunctionsFromType(_MBTI, isMBTI) {
var stack = ["", ""];
var firstFunction = "";
var secondFunction = "";
if (isMBTI) {
if (_MBTI.substring(0,1)==="I") {
if (_MBTI.substring(3)==="P") {
firstFunction = _MBTI.substring(2,3)+"i";
secondFunction = _MBTI.substring(1,2)+"e";
} else {
firstFunction = _MBTI.substring(1,2)+"i";
secondFunction = _MBTI.substring(2,3)+"e";
}
} else {
if (_MBTI.substring(3)==="J") {
firstFunction = _MBTI.substring(2,3)+"e";
secondFunction = _MBTI.substring(1,2)+"i";
} else {
firstFunction = _MBTI.substring(1,2)+"e";
secondFunction = _MBTI.substring(2,3)+"i";
}
}
} else {
if (_MBTI.substring(0,1)==="E") firstFunction+="F";
else if (_MBTI.substring(0,1)==="L") firstFunction+="T";
else if (_MBTI.substring(0,1)==="I") firstFunction+="N";
else firstFunction+=_MBTI.substring(0,1);
if (_MBTI.substring(1,2)==="E") secondFunction+="F";
else if (_MBTI.substring(1,2)==="L") secondFunction+="T";
else if (_MBTI.substring(1,2)==="I") secondFunction+="N";
else secondFunction+=_MBTI.substring(1,2);
if (_MBTI.substring(2,3)==="I") {
firstFunction+="i";
secondFunction+="e";
} else {
firstFunction+="e";
secondFunction+="i";
}
}
stack[0] = firstFunction;
stack[1] = secondFunction;
return stack;
}
// From first two functions (in string form) to type
// returns type as a string
function getTypeFromFunctions(first, second, isMBTI) {
var type = "";
if (isMBTI) {
if (first.substring(1,2)==="i") {
type+="I";
if (first.substring(0,1)==="N" || second.substring(0,1)==="N") type+="N";
else type+="S";
if (first.substring(0,1)==="T" || second.substring(0,1)==="T") type+="T";
else type+="F";
if (first.substring(0,1)==="N" || first.substring(0,1)==="S") type+="J";
else type+="P";
} else {
type+="E";
if (first.substring(0,1)==="N" || second.substring(0,1)==="N") type+="N";
else type+="S";
if (first.substring(0,1)==="T" || second.substring(0,1)==="T") type+="T";
else type+="F";
if (first.substring(0,1)==="N" || first.substring(0,1)==="S") type+="P";
else type+="J";
}
} else {
if (first.substring(0,1)==="F") type+="E";
else if (first.substring(0,1)==="T") type+="L";
else if (first.substring(0,1)==="N") type+="I";
else type+=(first.substring(0,1));
if (second.substring(0,1)==="F") type+="E";
else if (second.substring(0,1)==="T") type+="L";
else if (second.substring(0,1)==="N") type+="I";
else type+=(second.substring(0,1));
if (first.substring(1,2)==="i") type+="I";
else type+="E";
}
return type;
}
////////////////////////////////////////////////////////////////////////////
// From type to numbers
// returns an int[2]
/* NUMBERS TO FUNCTION KEY
111: Ti
110: Te
101: Fi
100: Fe
911: Ni
910: Ne
901: Si
900: Se
*/
function getNumbersFromType(_MBTI, isMBTI) {
var stack = [0, 0];
var f = getFunctionsFromType(_MBTI, isMBTI);
var firstFunction = f[0];
var secondFunction = f[1];
var intfirstFunction, intsecondFunction;
var first1 = 9;
var second1 = 0;
var third1 = 0;
if (firstFunction.substring(0,1)==="T" || firstFunction.substring(0,1)==="F") first1 = 1;
if (firstFunction.substring(0,1)==="T" || firstFunction.substring(0,1)==="N") second1 = 1;
if (firstFunction.substring(1,2)==="i") third1 = 1;
intfirstFunction = first1*100+second1*10+third1;
var first2 = 9;
var second2 = 0;
var third2 = 0;
if (secondFunction.substring(0,1)==="T" || secondFunction.substring(0,1)==="F") first2 = 1;
if (secondFunction.substring(0,1)==="T" || secondFunction.substring(0,1)==="N") second2 = 1;
if (secondFunction.substring(1,2)==="i") third2 = 1;
intsecondFunction = first2*100+second2*10+third2;
stack[0] = intfirstFunction;
stack[1] = intsecondFunction;
return stack;
}
// From numbers to type
// returns type as a string
function getTypeFromNumbers(first, second, isMBTI) {
var first1 = "";
var second1 = "";
if (Math.floor(first/100)==1) {
if ((Math.floor(first/10))%10==1) first1+="T";
else first1+="F";
} else {
if ((Math.floor(first/10))%10==1) first1+="N";
else first1+="S";
}
if (first%10==1) first1+="i";
else first1+="e";
if (Math.floor(second/100)==1) {
if ((Math.floor(second/10))%10==1) second1+="T";
else second1+="F";
} else {
if ((Math.floor(second/10))%10==1) second1+="N";
else second1+="S";
}
if (second%10==1) second1+="i";
else second1+="e";
return getTypeFromFunctions(first1, second1, isMBTI);
}