@agarimo/cartesian

1.0.1 • Public • Published

cartesian

Computes the cartesian product of arrays

Examples

const { cartesian } = require('@agarimo/cartesian');
const input = [[1, 2], [3, 4, 5], [6], [7, 8]];
const actual = cartesian(input);
console.log(actual);
// [
//   [ 1, 3, 6, 7 ], [ 1, 3, 6, 8 ],
//   [ 1, 4, 6, 7 ], [ 1, 4, 6, 8 ],
//   [ 1, 5, 6, 7 ], [ 1, 5, 6, 8 ],
//   [ 2, 3, 6, 7 ], [ 2, 3, 6, 8 ],
//   [ 2, 4, 6, 7 ], [ 2, 4, 6, 8 ],
//   [ 2, 5, 6, 7 ], [ 2, 5, 6, 8 ]
// ]

You can have elements that are not an array

const { cartesian } = require('@agarimo/cartesian');
const input = [[1, 2], [3, 4, 5], 6, [7, 8]];
const actual = cartesian(input);
console.log(actual);
// [
//   [ 1, 3, 6, 7 ], [ 1, 3, 6, 8 ],
//   [ 1, 4, 6, 7 ], [ 1, 4, 6, 8 ],
//   [ 1, 5, 6, 7 ], [ 1, 5, 6, 8 ],
//   [ 2, 3, 6, 7 ], [ 2, 3, 6, 8 ],
//   [ 2, 4, 6, 7 ], [ 2, 4, 6, 8 ],
//   [ 2, 5, 6, 7 ], [ 2, 5, 6, 8 ]
// ]

Readme

Keywords

none

Package Sidebar

Install

npm i @agarimo/cartesian

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

5.48 kB

Total Files

9

Last publish

Collaborators

  • jesus-seijas