Skip to content

Computes the cartesian product of arrays provided by an array or an object

License

Notifications You must be signed in to change notification settings

alexindigo/cartesian

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cartesian

Computes the cartesian product of arrays provided by an array or an object

Build Status Coverage Status

Install

npm install cartesian --save

Examples

var cartesian = require('cartesian');

Array or arrays:

cartesian([
  ['A', 'B', 'C'],
  ['M'],
  ['X', 'Y'],
  'Z'
]);

// =>
// [
//   [ 'A', 'M', 'X', 'Z' ],
//   [ 'A', 'M', 'Y', 'Z' ],
//   [ 'B', 'M', 'X', 'Z' ],
//   [ 'B', 'M', 'Y', 'Z' ],
//   [ 'C', 'M', 'X', 'Z' ],
//   [ 'C', 'M', 'Y', 'Z' ]
// ]

Object with array properties:

cartesian({
  cdn  : ['image1', 'image2'],
  path : '/dir',
  files: ['file1', 'file2', 'file3']
});

// =>
// [
//   { cdn: 'image1', path: '/dir', files: 'file1' },
//   { cdn: 'image1', path: '/dir', files: 'file2' },
//   { cdn: 'image1', path: '/dir', files: 'file3' },
//   { cdn: 'image2', path: '/dir', files: 'file1' },
//   { cdn: 'image2', path: '/dir', files: 'file2' },
//   { cdn: 'image2', path: '/dir', files: 'file3' }
// ]

For more examples check out test.js.

License

MIT

About

Computes the cartesian product of arrays provided by an array or an object

Resources

License

Stars

Watchers

Forks

Packages

No packages published