I need some help
I have two arrays:
First array have Boolean elements. (It’s true when button is active , and false if not)
The second one strings where “0”(active) or “1” (inactive).
JavaScript
x
3
1
let arrayBotoesCategorias = [iconCategoriaIndividual, iconCategoriaGrupo, iconCategoriaIndoor, iconCategoriaOutdoor, iconCategoriaAquatico,iconCategoriaNatureza];
2
let arrayCategorias = [item.individual, item.grupo, item.indoor, item.outdoor, item.aquatico, item.natureza];
3
To understand better , PaintBall have grupo(group), indoor, outdoor and natureza(nature) activated. The rest are inactive. Like this
JavaScript
1
7
1
individual: "0",
2
grupo: "1",
3
indoor: "1",
4
outdoor: "1",
5
aquatico: "0",
6
natureza: "1",
7
What I need it’s the following but of course with another solution:
JavaScript
1
6
1
if(arrayBotoesCategorias[1] == true && arrayBotoesCategorias[2] == true && arrayBotoesCategorias[3] == true && arrayBotoesCategorias[5] == true){
2
if(arrayCategorias[1] == "1" && arrayCategorias[2] == "1" && arrayCategorias[3] == "1" && arrayCategorias[5] == "1"){
3
return(itemSection)
4
}
5
}
6
When a element from the first array is true and the same position of the second is == “1” , return something.
In this example image , I Want to show the images that have those 3 tables (outdoor, aquatico and natureza with value “1”);
Advertisement
Answer
Already solved Thanks for the help!
JavaScript
1
54
54
1
var controlCategorias = 0;
2
var errorControlCategorias = 0;
3
4
for(var i = 0; i<arrayBotoesCategorias.length; i++){
5
switch (i){
6
case 0:
7
if((arrayBotoesCategorias[0] && item.individual == "1") || (!arrayBotoesCategorias[0] && item.individual == "0") || (!arrayBotoesCategorias[0] && item.individual == "1")) {
8
controlCategorias++;
9
}else{
10
errorControlCategorias++;
11
}
12
break;
13
case 1:
14
if((arrayBotoesCategorias[1] && item.grupo == "1") || (!arrayBotoesCategorias[1] && item.grupo == "0") || (!arrayBotoesCategorias[1] && item.grupo == "1")) {
15
controlCategorias++;
16
}else{
17
errorControlCategorias++;
18
}
19
break;
20
case 2:
21
if((arrayBotoesCategorias[2] && item.indoor == "1") || (!arrayBotoesCategorias[2] && item.indoor == "0") || (!arrayBotoesCategorias[2] && item.indoor == "1")) {
22
controlCategorias++;
23
}else{
24
errorControlCategorias++;
25
}
26
break;
27
case 3:
28
if((arrayBotoesCategorias[3] && item.outdoor == "1") || (!arrayBotoesCategorias[3] && item.outdoor == "0") || (!arrayBotoesCategorias[3] && item.outdoor == "1")) {
29
controlCategorias++;
30
}else{
31
errorControlCategorias++;
32
}
33
break;
34
case 4:
35
if((arrayBotoesCategorias[4] && item.aquatico == "1") || (!arrayBotoesCategorias[4] && item.aquatico == "0") || (!arrayBotoesCategorias[4] && item.aquatico == "1")) {
36
controlCategorias++;
37
}else{
38
errorControlCategorias++;
39
}
40
break;
41
case 5:
42
if((arrayBotoesCategorias[5] && item.natureza == "1") || (!arrayBotoesCategorias[5] && item.natureza == "0") || (!arrayBotoesCategorias[5] && item.natureza == "1")) {
43
controlCategorias++;
44
}else{
45
errorControlCategorias++;
46
}
47
break;
48
}
49
50
}
51
52
if(controlCategorias > 0 && errorControlCategorias == 0){
53
return itemSection;
54
}