Andy N
Andy N

Reputation: 1123

Calculating possible combinations of sets of numbers

I have these sets of numbers

[1, 2] [1,2,3] [1,2]

I need an javascript algorithm that can calculate the possible combinations of these sets or any number of sets. So the number of possible combinations is 2 x 3 x 2 = 12.

The possible combinations are:

1, 1, 1
1, 1, 2
1, 2, 1
1, 2, 2
1, 3, 1
1, 3, 2
2, 1, 1
2, 1, 2
2, 2, 1
2, 2, 2
2, 3, 1
2, 3, 2

Is there some npm library that can do this calculation or this requires a custom algorithm?

Upvotes: 0

Views: 230

Answers (1)

You have a js-combinatorics check https://www.npmjs.com/package/js-combinatorics

Upvotes: 2

Related Questions