get dictionnary of attributes, key and value
continuous-integration/drone/push Build is passing Details

pull/88/head
Bastien JACQUELIN 2 years ago
parent e87dec89fc
commit 5c54ffa32f

@ -3,4 +3,5 @@ const TAB_NUMBER = [1,2,3,4,5];
const TAB_SHAPE = ['diamond','oval','wave','star','triangle'];
const TAB_FILLING = ['empty','stripped','full','pointed','squared'];
const TAB_OUTLINE = ['full','dotted','hyphen','cloudy','sharpy'];
const ATTRIBUTES=[TAB_COLOR,TAB_NUMBER,TAB_SHAPE,TAB_FILLING,TAB_OUTLINE]
const ATTRIBUTES=[TAB_COLOR,TAB_NUMBER,TAB_SHAPE,TAB_FILLING,TAB_OUTLINE];
const IDX_ATTRIBUTES=["color","number","shape","filling","outline"];

@ -3,17 +3,41 @@ class Factory{
let length=arrayOfAttributes.length
this.product=this.concreteCardCreation(arrayOfAttributes,length);
console.log("arrayOfAttributes",this.funArrayOfAttributes(arrayOfAttributes));
console.log("attributesDictionnary",this.attributesDictionnary(arrayOfAttributes,this.funArrayOfAttributes(arrayOfAttributes)))
}
funArrayOfAttributes(arrayOfAttributes){
/**
*
* @param {*} arrayOfIdxAttributes index of attributes in ATTRIBUTES
* @returns array of all attributes
*/
funArrayOfAttributes(arrayOfIdxAttributes){
let attr=[];
let l=arrayOfAttributes.length;
arrayOfAttributes.forEach(e => {
for (let i=0;i<l;l++){
attr.push(e[i]);
let l=arrayOfIdxAttributes.length;
arrayOfIdxAttributes.forEach(e => {
for (let i=0;i<l;i++){
attr.push(ATTRIBUTES[e][i]);
}
});
return attr;
}
/**
*
* @param {*} arrayOfIdxAttributes index of attributes in ATTRIBUTES
* @param {*} arrayOfAllAttributes array of all attributes
* @returns dictionnary with key : attribute and value : array of the possibilities of attributes
*/
attributesDictionnary(arrayOfIdxAttributes,arrayOfAllAttributes){
let l=arrayOfIdxAttributes.length;
let dico={};
for (let i=0;i<l;i++){
let tmp=[]
for(let j=0;j<l;j++){
tmp.push(arrayOfAllAttributes[(i*l)+j]);
}
dico[IDX_ATTRIBUTES[arrayOfIdxAttributes[i]]]=tmp;
}
return dico;
}

Loading…
Cancel
Save