I need to expand(from 2 to a maximum of 10) and optimize some model importing, but i just can't think of a good way to check a javascript object for matching values other than a ton of if statements, So i thought i would ask here and see if there are any experienced js devs that knows of a good, lightweight way to accomplish this..
Basic structure:
//a is the object, it contains some basic, unrelated information and
//either 2, 6 or 10 id's & id2's
//unused id's have a value of 0.
//Sorry for the faulty variables, i was in a rush and just needed to show that xid & xid2 fit together and yid & yid2 fit together, etc.
//input 1
a.1Id = x; //Primary, Desides the actual model to import
a.1Id2 = y; //Secondary, Desides version of the model, specific colours, features, etc
//input 2
a.2Id = z;
a.2Id2 = x;
(up to a maximum of 10 inputs, a.10Id & Id2)
Now, i need to check for matches..
If 1Id is the same as 2Id and 1Id2 is the same as 2Id2, only import the model once.
When there are only two model inputs, it's rather simple.
//the import is not actually structured as var importX,
//they are pushed to another object and then the loader loads each of them with a for..loop
if (a.1Id === a.2Id && a.1Id2 === a.2Id2){
var import1 = a.1Id;
var import12 = a.1Id2;
} else {
var import1 = a.1Id;
var import12 = a.1Id2;
var import2 = a.2Id;
var import22 = a.2Id2;
}
But beyond that, you can imagine that it starts getting rather heavy with if statements to check how many and if any of them are the same..
So to wrap it up, i'm basicly hoping that it is possible with some kind of function or algorythm, to check all xId and xId2 input values if they are matching with any of the others and then only send one of the matching inputs to the loader, thus avoiding importing the same model several times.