计算数字集的可能组合

Calculating possible combinations of sets of numbers

我有这组数字

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

我需要一个 javascript 算法来计算这些集合或任意数量集合的可能组合。所以可能的组合数是 2 x 3 x 2 = 12.

可能的组合是:

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

是否有一些 npm 库可以执行此计算或者这需要自定义算法?

您有一个 js-combinatorics 检查 https://www.npmjs.com/package/js-combinatorics