# power-cartesian-product

> powerful cartesian product

Latest version **0.0.6** (published 2020-02-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install power-cartesian-product
pnpm add power-cartesian-product
yarn add power-cartesian-product
bun add power-cartesian-product
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.0.6 |
| Published | 2020-02-19 |
| First published | 2019-08-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 81.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | fisker Cheung |
| Maintainers | fisker |

## Links

- npm: https://www.npmjs.com/package/power-cartesian-product
- Repository: https://github.com/fisker/power-cartesian-product
- Homepage: https://github.com/fisker/power-cartesian-product#readme
- Issues: https://github.com/fisker/power-cartesian-product/issues
- Funding: https://github.com/fisker/power-cartesian-product?sponsor=1
- npm.io page: https://npm.io/package/power-cartesian-product

## Recent versions

- 0.0.6 (latest) — 2020-02-19
- 0.0.5 — 2019-11-09
- 0.0.4 — 2019-08-30
- 0.0.3 — 2019-08-02

## README

# power-cartesian-product

> powerful cartesian product

this module was named `fast-cartesian-product` before `v0.0.3`, now it's split into to two modules:

- [`fast-cartesian-product`](https://github.com/fisker/fast-cartesian-product)

  focusing on speed, and only work on arrays

- [`power-cartesian-product`](https://github.com/fisker/power-cartesian-product)

  focusing on unlimited combinations, less memory, more data types

## Examples

```js
import PowerCartesianProduct from 'power-cartesian-product'

const inputs = [
  [0, 1],
  ['A', 'B'],
]

for (const combination of new PowerCartesianProduct(inputs)) {
  console.log(combination)
}
```

more examples

```sh
git clone https://github.com/fisker/power-cartesian-product.git
cd fast-cartesian-product
yarn
node -r esm examples/standard-52-card-deck.js
node -r esm examples/any-iterable-type.js
node -r esm examples/big-combinations.js
```

## Files

```text
dist/
├─ index.common.js  ( CommonJS )
├─ index.js         ( UMD )
├─ index.min.js     ( UMD, compressed )
├─ index.mjs        ( ES Module )
└─ index.min.mjs    ( ES Module, compressed )
```

## API

### combinations = new PowerCartesianProduct(sets)

Returns: combinations

#### sets

type: `iterable | arrayLike | GeneratorFunction`

\*notice: `GeneratorFunction` is supported, not `generator` yet, [#57](https://github.com/fisker/power-cartesian-product/pull/57)

#### combinations

instance of `PowerCartesianProduct`

it's not `Array`, also no `length`

to get `Array`

```js
[...combinations]

// OR

Array.from(...combinations)

// OR

const array = []

let (const combination of combinations) {
  array.push(combination)
}

// es5

var array = []
var iterator = combinations[PowerCartesianProduct.SYMBOL_ITERATOR]()
var data
while (!(data = iterator.next()).done) {
  array.push(data.value)
}
```

to get `Set`

```js
new Set(combinations)
```

#### PowerCartesianProduct#get(index)

get nth combination

Returns: `array`

```js
// 3rd combination
new PowerCartesianProduct([
  [0, 1],
  ['A', 'B'],
]).get(2)
// -> [1, 'A']
```

#### PowerCartesianProduct#getIndexes(index)

get nth combination indexes

Returns: `array<number>`

```js
// 3rd combination indexes
new PowerCartesianProduct([
  [0, 1],
  ['A', 'B'],
]).getIndexes(2)
// -> [1, 0]
```

#### PowerCartesianProduct#size

a getter to get `size` of combinations, this might be `Infinity` for big combinations.

Returns: `int | infinity`

```js
new PowerCartesianProduct([
  [0, 1],
  ['A', 'B'],
]).size
// -> 4

new PowerCartesianProduct(new Array(256).fill(new Array(16))).size
// -> Infinity
```

#### PowerCartesianProduct#bigSize

a getter to get BigInt `size` of combinations.

Returns: `BigInt`

```js
new PowerCartesianProduct([
  [0, 1],
  ['A', 'B'],
]).bigSize
// -> 4n

new PowerCartesianProduct(new Array(33).fill(new Array(2 ** 32 - 1))).bigSize
// -> 772103316315349105706014416063813378269318666861765024749836830511609335567106186231578700102953323105081739246412669785553431723085370935750037827673052894357512235463946499050426982824119747058048805090828544034771248058426863536672304703225363101118206353134873876903786099067350665495893380022607743740081787109375n
```

#### PowerCartesianProduct.SYMBOL_ITERATOR

symbol to get Iterator,
for environment without `Symbol`, it's string `@@iterator`, otherwise it's `Symbol.iterator`

if you are not sure, you should always use `combinations[PowerCartesianProduct.SYMBOL_ITERATOR]()`

```js
var iterator = combinations[PowerCartesianProduct.SYMBOL_ITERATOR]()
iterator.next() // {value: [0, 1], done: false}
```

---
_Source: https://npm.io/package/power-cartesian-product · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
