-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutiliteur.js
174 lines (111 loc) · 3.29 KB
/
utiliteur.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
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
function clonage(objet) {
let nouveau = document.createElement("strong");
nouveau.innerHTML = objet.innerText;
nouveau.style["border-top"] = objet.style['border-top'];
return nouveau;
}
function inverseur(prop, expre) {
expre.forEach(function (value, key) {
if (key.length > 1) {
let temp = [].concat(prop.get(key[1]))
expre.set(key, temp.reverse())
} else {
expre.set(key, prop.get(key))
}
})
return expre
}
function tableDeVerite(propositions, expression) {
let taille = 2 ** propositions.length;
let n;
let mapProp = new Map();
let expre = new Map()
for (let index = 0; index < propositions.length; index++) {
n = (taille / 2 ** (index + 1));
let c = 1;
let m = [];
for (let j = 0; j < 2 ** (index + 1); j++) {
c = (c == 1) ? 0 : 1;
for (let k = 0; k < n; k++) {
m.push(c);
}
}
mapProp.set(propositions[index], m)
}
for (prop in expression) {
alert(expression[prop])
expre.set(expression[prop], [])
}
let clona = inverseur(mapProp, expre)
clona.forEach(function (value, key) {
//alert(key + ':' + value)
})
return clona
}
function calculBinaire(tab, i) {
alert(i);
let k = i + 1;
if (tab.length >= k) {
if (tab[k] == "+") {
return parseInt(tab[i]) | resulatat(tab, k + 1);
} else if (tab[k] == "*") {
return parseInt(tab[i]) & resulatat(tab, k + 1);
}
} {
return parseInt(tab[i]);
}
}
// utilisation pour la suppression personnalisée
function supprimer(tabAsupprimer, debut, fin) {
remplacement = []
for (let i = debut; i <= fin; i++) {
tabAsupprimer[i] = "";
}
tabAsupprimer[debut] = "R";
for (let j = 0; j < tabAsupprimer.length; j++) {
if (tabAsupprimer[j] != "") {
remplacement.push(tabAsupprimer[j])
}
}
tabAsupprimer = remplacement;
return tabAsupprimer;
}
// traitement des parenthèses
function traitementPriorite(expression, dico) {
if (expression.includes("(") != false) {
let ind = 0;
tab = []
prop = []
index = expression.indexOf(")")
for (let i = 0; i < index; i++) {
if (expression[i] == "(") {
inde = i;
}
}
for (let j = inde; j <= index; j++) {
tab.push(expression[j])
}
alert(inde + "--" + index)
alert(expression)
expression = supprimer(expression, inde, index);
dico.push(tab);
priorite(expression, dico);
} else {
return dico;
}
}
// ajout de la bare dans une proposition pour signifier l'inverse de celle ci
function bar(listEnfants, parent) {
let nouveau = document.createElement("a");
if (parent.children.length >= 3) {
let ta = [];
for (var i = listEnfants.length - 1; i >= 0; i--) {
ta.push(listEnfants[i]);
}
for (var i = ta.length - 1; i >= 0; i--) {
nouveau.appendChild(ta[i]);
}
parent.appendChild(nouveau);
}
}
export { clonage, calculBinaire, inverseur, tableDeVerite, traitementPriorite, supprimer,bar }