I'm trying to write a function to give permutations given an array of data like this:
[
{ ent: 'animal', vals: [ 'dog', 'cat' ] },
{ ent: 'color', vals: [ 'red', 'blue', 'green' ] },
{ ent: 'owner', vals: [ 'bob', 'david' ] }
]
I'd like a result like:
[
[animal: dog, color; red, owner: bob],
[animal: dog, color: red, owner: david],
[animal: dog, color: blue, owner: bob],
// ... etc (values as strings)
]
or even just
[ dog, red, bob ],
[ dog, red, david ],
[ dog, blue, bob ],
// etc (as strings)
basically the Unique set like:
111
112
113
121
122
123
// etc
Unique combinations that have a value for each of the options.
I've been struggling with some type of recursive function to to this without too much luck!
related for simple strings Permutations in JavaScript?
I've found some libraries for dealing with Permutations but nothing that seems to work with this type of structures.
Thanks!