1.0.0 • Published 4 years ago

lodash.multipermutations v1.0.0

Weekly downloads
9
License
MIT
Repository
github
Last release
4 years ago

lodash.multipermutations

_.multipermutations(collection, n)

Calculates all possible multipermutations of a certain size.

argumentdescription
collectionA collection of distinct values to calculate the multipermutations from.
nThe 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']

see also