https://github.com/seregpie/lodash.multicombinations
Calculates all possible combinations with repetition of a certain size.
https://github.com/seregpie/lodash.multicombinations
array collection combinatorics lodash mixin multicombination
Last synced: 5 months ago
JSON representation
Calculates all possible combinations with repetition of a certain size.
- Host: GitHub
- URL: https://github.com/seregpie/lodash.multicombinations
- Owner: SeregPie
- License: mit
- Created: 2020-06-04T09:53:20.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-06-04T11:56:11.000Z (almost 5 years ago)
- Last Synced: 2024-10-10T22:32:33.685Z (7 months ago)
- Topics: array, collection, combinatorics, lodash, mixin, multicombination
- Language: JavaScript
- Homepage:
- Size: 3.91 KB
- Stars: 5
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lodash.multicombinations
`_.multicombinations(collection, n)`
Calculates all possible combinations with repetition of a certain size.
| argument | description |
| ---: | :--- |
| `collection` | A collection of distinct values to calculate the combinations from. |
| `n` | The number of values to combine. |Returns a new array.
## setup
### npm
```shell
npm i lodash.multicombinations
```### ES module
```javascript
import 'lodash.multicombinations';
import _ from 'lodash';
```### Node
```javascript
require('lodash.multicombinations');
let _ = require('lodash');
```### browser
```html
```
## usage
```javascript
let multicombinations = _.multicombinations([0, 1], 3);
// => [[0, 0, 0], [0, 0, 1], [0, 1, 1], [1, 1, 1]]
```---
Also accepts array-like values.
```javascript
let multicombinations = _('abcde').multicombinations(2).map(v => _.join(v, '')).value();
// => ['aa', 'ab', 'ac', 'ad', 'ae', 'bb', 'bc', 'bd', 'be', 'cc', 'cd', 'ce', 'dd', 'de', 'ee']
```## see also
- [lodash.combinations](https://github.com/SeregPie/lodash.combinations)
- [lodash.permutations](https://github.com/SeregPie/lodash.permutations)
- [lodash.multipermutations](https://github.com/SeregPie/lodash.multipermutations)
- [lodash.product](https://github.com/SeregPie/lodash.product)