https://github.com/seregpie/lodash.product
Calculates the Cartesian product between multiple collections.
https://github.com/seregpie/lodash.product
array cartesian-product collection combinatorics iterable javascript lodash mixin plugin
Last synced: 5 months ago
JSON representation
Calculates the Cartesian product between multiple collections.
- Host: GitHub
- URL: https://github.com/seregpie/lodash.product
- Owner: SeregPie
- License: mit
- Created: 2016-12-23T18:57:06.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2022-12-18T12:21:52.000Z (over 2 years ago)
- Last Synced: 2024-12-12T01:46:31.038Z (5 months ago)
- Topics: array, cartesian-product, collection, combinatorics, iterable, javascript, lodash, mixin, plugin
- Language: JavaScript
- Homepage:
- Size: 16.6 KB
- Stars: 18
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lodash.product
`_.product(...collections)`
Calculates the Cartesian product between multiple collections.
| argument | description |
| ---: | :--- |
| `collections` | Collections to calculate the Cartesian product from. |Returns a new array.
## setup
### npm
```shell
npm i lodash.product
```### ES module
```javascript
import 'lodash.product';
import _ from 'lodash';
```### Node
```javascript
require('lodash.product');
let _ = require('lodash');
```### browser
```html
```
## usage
```javascript
let product = _.product([false, true], ['a', 'b', 'c'], [{}]);
// => [[false, 'a', {}], [false, 'b', {}], [false, 'c', {}], [true, 'a', {}], [true, 'b', {}], [true, 'c', {}]]
```---
```javascript
let array = [1, 2, 3];
let product = _.product(array, array);
// => [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3]]
```