dankogai / js-combinatorics

power set, combination, permutation and more in JavaScript
MIT License
742 stars 97 forks source link

Can cartesianProduct accept List of List? #42

Closed yiu31802 closed 7 years ago

yiu31802 commented 7 years ago

Example from README.md:

cp = Combinatorics.cartesianProduct([0, 1, 2], [0, 10, 20], [0, 100, 200]);

Is there a way to do like this?

var x = [[0, 1, 2], [0, 10, 20], [0, 100, 200]]
cp = Combinatorics.cartesianProduct(x);
blanchg commented 7 years ago

You might be able to do it like this:

var x = [[0, 1, 2], [0, 10, 20], [0, 100, 200]]
Combinatorics.cartesianProduct.apply(null, x);
yiu31802 commented 7 years ago

Wow that works, knowing that this is a javascript technique... Thank you very much @blanch