lodash.combinations
TypeScript icon, indicating that this package has built-in type declarations

18.11.1 • Public • Published

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

npm i lodash.combinations

import 'lodash.combinations';
import _ from 'lodash';

CDN

<script src="https://unpkg.com/lodash"></script>
<script src="https://unpkg.com/lodash.combinations"></script>

usage

let combinations = _.combinations([true, {a: 1}, null], 2);
// => [[true, {a: 1}], [true, null], [{a: 1}, null]]

Calculate all possible combinations of all possible sizes.

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

Package Sidebar

Install

npm i lodash.combinations

Weekly Downloads

3,997

Version

18.11.1

License

MIT

Unpacked Size

4.77 kB

Total Files

5

Last publish

Collaborators

  • seregpie