Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Compute the cartesian product of two array-like objects. i.e., every possible pairing of their elements.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 README.md
Octocat-spinner-32 index.js
Octocat-spinner-32 package.json
README.md

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]
                                             ] */
Something went wrong with that request. Please try again.