My goal is to create a part of code that would generate all possible combinations without duplicates (combinations with same elements, no matter what their sequence is) with data from a JSON file. My JSON file looks like this:
[
{
"COLLECTION": "Assault",
"WEAPON": "SG 553",
"SKIN": "Tornado",
"GRADE": "Consumer Grade"
},
{
"COLLECTION": "Assault",
"WEAPON": "UMP-45",
"SKIN": "Caramel",
"GRADE": "Consumer Grade"
},
{
"COLLECTION": "Vertigo",
"WEAPON": "Five-SeveN",
"SKIN": "Candy Apple ",
"GRADE": "Industrial Grade"
}, ...
]
Combinations would be generated in the following way:
[
"COMBINATION 1":[
{
"COLLECTION": "Assault",
"WEAPON": "SG 553",
"SKIN": "Tornado",
"GRADE": "Consumer Grade"
},
{
"COLLECTION": "Assault",
"WEAPON": "UMP-45",
"SKIN": "Caramel",
"GRADE": "Consumer Grade"
},
{
"COLLECTION": "Assault",
"WEAPON": "Five-SeveN",
"SKIN": "Candy Apple ",
"GRADE": "Industrial Grade"
}, ...
],
"COMBINATION 2":[
{
"COLLECTION": "Assault",
"WEAPON": "SG 553",
"SKIN": "Tornado",
"GRADE": "Consumer Grade"
},
{
"COLLECTION": "Aztec",
"WEAPON": "M4A4",
"SKIN": "Jungle Tiger",
"GRADE": "Industrial Grade"
},
{
"COLLECTION": "Aztec",
"WEAPON": "Tec-9",
"SKIN": "Ossified",
"GRADE": "Mil-Spec"
}, ...
],...
]
Note that in this case both combinations have the same elements and therefore shouldn't be noted twice. That means that as long as there are elements in a combination that are same to another possible combination (no matter what sequence they are in) it counts as one combination (every combination will have 10 elements, and would be distinct from another based on the "SKIN" attribute values):
[
"COMBINATION 1":[
{
"COLLECTION": "Vertigo",
"WEAPON": "SG 553",
"SKIN": "Tornado",
"GRADE": "Consumer Grade"
},
{
"COLLECTION": "Assault",
"WEAPON": "UMP-45",
"SKIN": "Caramel",
"GRADE": "Consumer Grade"
},
{
"COLLECTION": "Assault",
"WEAPON": "Five-SeveN",
"SKIN": "Candy Apple ",
"GRADE": "Industrial Grade"
},...
],
"COMBINATION 2":[
{
"COLLECTION": "Assault",
"WEAPON": "Five-SeveN",
"SKIN": "Candy Apple ",
"GRADE": "Industrial Grade"
},
{
"COLLECTION": "Vertigo",
"WEAPON": "SG 553",
"SKIN": "Tornado",
"GRADE": "Consumer Grade"
},
{
"COLLECTION": "Assault",
"WEAPON": "UMP-45",
"SKIN": "Caramel",
"GRADE": "Consumer Grade"
},...
],...
Also note that the same item can appear in a combination multiple times (up to 10) and that I'm workig with a JSON file of around 1500 elements, so efficiency is key. To sum it up the final product should look something like this: https://textuploader.com/1du6o
This is also a kinda similar problem, but less complex: Permutations in JavaScript?
I've tried to sort this out with bubble sort and such, but haven't succeeded thus far. If you have any ideas how to make this happen I'd love to hear them.