cartesian-product

Compute the cartesian product of zero or more array-like objects. i.e., the array containing every possible grouping of their elements.

npm install cartesian-product
2 downloads in the last week
14 downloads in the last month

Compute the cartesian product of zero or more array-like objects. i.e., the array containing every possible grouping of their elements.

Examples

var cp = require('cartesian-product')

cp(['a', 'b'], [1, 2])  /* → [ ['a', 1]
                             , ['a', 2]
                             , ['b', 1]
                             , ['b', 2]
                             ] */

cp([0, 1, 2], [true, false])    /* → [ [0, true]
                                     , [0, false]
                                     , [1, true]
                                     , [1, false]
                                     , [2, true]
                                     , [2, false]
                                     ] */

cp(['a', 'b'], [1, 2], [true, false])   /* → [ ['a', 1, true]
                                             , ['a', 1, false]
                                             , ['a', 2, true]
                                             , ['a', 2, false]
                                             , ['b', 1, true]
                                             , ['b', 1, false]
                                             , ['b', 2, true]
                                             , ['b', 2, false]
                                             ] */
npm loves you