-
Notifications
You must be signed in to change notification settings - Fork 97
Open
Description
I have a set of elements with possible duplication.
I need to get all possible permutations of combinations but removing duplicates.
Like so:
const all = ['a', 'a', 'b'];
const cmb = Combinatorics.permutationCombination(all);
console.log(cmb.toArray());Expected output is:
[ [ 'a' ],
[ 'b' ],
[ 'a', 'a' ],
[ 'a', 'b' ],
[ 'b', 'a' ],
[ 'a', 'a', 'b' ],
[ 'a', 'b', 'a' ],
[ 'b', 'a', 'a' ] ]but instead, I am getting
[ [ 'a' ],
[ 'a' ],
[ 'b' ],
[ 'a', 'a' ],
[ 'a', 'a' ],
[ 'a', 'b' ],
[ 'b', 'a' ],
[ 'a', 'b' ],
[ 'b', 'a' ],
[ 'a', 'a', 'b' ],
[ 'a', 'b', 'a' ],
[ 'a', 'a', 'b' ],
[ 'a', 'b', 'a' ],
[ 'b', 'a', 'a' ],
[ 'b', 'a', 'a' ] ]So far I have been able to work around this with a control list and checking while iterating. I could refactor this into a lazyFilter that checks such list, but it would pretty much be the same as I still need to externally keep track of the already visited permutations.
Any way to keep this contained within the library?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels