@extra-array/cartesian-product
Version:
Lists cartesian product of arrays.
62 lines (48 loc) • 2.06 kB
Markdown
Lists cartesian product of arrays.
[:package:](https://www.npmjs.com/package/@extra-array/cartesian-product)
[:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array)
[:running:](https://npm.runkit.com/@extra-array/cartesian-product)
[:vhs:](https://asciinema.org/a/332024)
[:moon:](https://www.npmjs.com/package/@extra-array/cartesian-product.min)
[:scroll:](https://unpkg.com/@extra-array/cartesian-product/)
[:newspaper:](https://nodef.github.io/extra-array/)
[:blue_book:](https://github.com/nodef/extra-array/wiki/)
> Similar: [cartesianProduct], [zip].
> This is part of package [extra-array].
[extra-array]: https://www.npmjs.com/package/extra-array
<br>
```javascript
array.cartesianProduct(xs, [fm]);
// xs: arrays
// fm: map function (vs, i)
```
```javascript
const array = require("extra-array");
var x = [1, 2, 3];
var y = [10, 20, 30];
array.cartesianProduct([x, y]);
// [
// [ 1, 10 ], [ 1, 20 ],
// [ 1, 30 ], [ 2, 10 ],
// [ 2, 20 ], [ 2, 30 ],
// [ 3, 10 ], [ 3, 20 ],
// [ 3, 30 ]
// ]
array.cartesianProduct([x, y], ([a, b]) => a + b);
// [
// 11, 21, 31, 12, 22,
// 32, 13, 23, 33
// ]
```
<br>
<br>
## References
- [Data.Set.cartesianProduct: Haskell](http://hackage.haskell.org/package/containers-0.6.2.1/docs/Data-Set.html#v:cartesianProduct)
- [List-Extra.cartesianProduct: elm](https://package.elm-lang.org/packages/elm-community/list-extra/latest/List-Extra#cartesianProduct)
- [itertools.product: Python](https://docs.python.org/3/library/itertools.html#itertools.product)
- [Guava.Lists: Java](https://guava.dev/releases/23.5-jre/api/docs/com/google/common/collect/Lists.html#cartesianProduct-java.util.List-)
- [fast-cartesian-product: @fisker](https://www.npmjs.com/package/fast-cartesian-product)
- [cartesian-product: @izaakschroeder](https://www.npmjs.com/package/cartesian-product)
- [cartesian: @alexindigo](https://www.npmjs.com/package/cartesian)
[cartesianProduct]: https://github.com/nodef/extra-array/wiki/cartesianProduct
[zip]: https://github.com/nodef/extra-array/wiki/zip