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
|
function calcInArray(){
var tab = [],cle="987654";
for(let m=0;m<=cle.length;m++){
[
[1, 4, 7, 10, 13, 16, 19, 22, 25, 28],
[2, 5, 8, 11, 14, 17, 20, 23, 26, 29],
[3, 6, 9, 12, 15, 18, 21, 24, 27, 30]
]
.map(function(elem,i){
if(elem.includes(m)){
!tab[m]?tab[m]=[]:'';//si tab[m] n'est pas défini, on l'initialise à [] tableau vide, sinon on ne fait rien
switch(i) {
case 0 :
tab[m][0]="a0";
tab[m][1]="a1";
break;
case 1:
tab[m][0] = "b0";
tab[m][1] = "b1";
tab[m][2] = "b2";
break;
case 2:
tab[m][0] = "c0";
tab[m][1] = "c1";
break;
}
}
});
}
return tab;
}
console.log(calcInArray()); |
Partager