lodash.multipermutations

1.0.0 • Public • Published

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']

see also

Package Sidebar

Install

npm i lodash.multipermutations

Weekly Downloads

824

Version

1.0.0

License

MIT

Unpacked Size

3.73 kB

Total Files

4

Last publish

Collaborators

  • seregpie