https://github.com/seregpie/lodash.combinations
Calculates all possible combinations without repetition of a certain size.
https://github.com/seregpie/lodash.combinations
Last synced: 5 months ago
JSON representation
Calculates all possible combinations without repetition of a certain size.
- Host: GitHub
- URL: https://github.com/seregpie/lodash.combinations
- Owner: SeregPie
- License: mit
- Created: 2016-12-05T19:27:28.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-06-05T10:05:35.000Z (almost 3 years ago)
- Last Synced: 2024-06-18T22:16:58.547Z (11 months ago)
- Language: JavaScript
- Homepage:
- Size: 27.3 KB
- Stars: 20
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lodash.combinations
`_.combinations(collection, k)`
Calculates all possible combinations without repetition of a certain size.
| argument | description |
| ---: | :--- |
| `collection` | A collection of distinct values to calculate the groups from. |
| `k` | A number as the size of each group. |Returns the calculated groups as an array of arrays.
## setup
```shell
npm i lodash.combinations
```---
```javascript
import 'lodash.combinations';
import _ from 'lodash';
```### CDN
```html
```
## usage
```javascript
let combinations = _.combinations([true, {a: 1}, null], 2);
// => [[true, {a: 1}], [true, null], [{a: 1}, null]]
```---
Calculate all possible combinations of all possible sizes.
```javascript
let combinations = _.flatMap([2, 4, 6], (v, i, a) => _.combinations(a, i + 1));
// => [[2], [4], [6], [2, 4], [2, 6], [4, 6], [2, 4, 6]]
```## see also
- [lodash.permutations](https://github.com/SeregPie/lodash.permutations)
- [lodash.multicombinations](https://github.com/SeregPie/lodash.multicombinations)
- [lodash.multipermutations](https://github.com/SeregPie/lodash.multipermutations)
- [lodash.product](https://github.com/SeregPie/lodash.product)