lodash.multipermutations
v1.0.0
Published
Calculates all possible multipermutations of a certain size.
Downloads
2,319
Maintainers
Readme
lodash.multipermutations
_.multipermutations(collection, n)
Calculates all possible multipermutations of a certain size.
| argument | description |
| ---: | :--- |
| collection
| A collection of distinct values to calculate the multipermutations from. |
| n
| The number of values to combine. |
Returns a new array.
setup
npm
npm i lodash.multipermutations
ES module
import 'lodash.multipermutations';
import _ from 'lodash';
Node
require('lodash.multipermutations');
let _ = require('lodash');
browser
<script src="https://unpkg.com/lodash"></script>
<script src="https://unpkg.com/lodash.multipermutations"></script>
usage
let multipermutations = _.multipermutations([0, 1], 3);
// => [[0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 0, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1]]
Also accepts array-like values.
let multipermutations = _('abc').multipermutations(2).map(v => _.join(v, '')).value();
// => ['aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc']