@nem035/combs

Simple utility to generate all combinations for a given array.

Usage no npm install needed!

<script type="module">
  import nem035Combs from 'https://cdn.skypack.dev/@nem035/combs';
</script>

README

Combs npm

Simple utility to generate all combinations for a given array.

Note: order doesn't matter, ["a", "b"] and ["b", "a"] are the same combination.

Usage

const combs = require("@nem035/combs");

const res = combs(["a", "b", "c"]);
/*
[
  ["a"],
  ["b"],
  ["c"],
  ["a", "b"],
  ["a", "c"],
  ["b", "c"],
  ["a", "b", "c"],
]
*/

Doesn't matter what's in the array:

const combs = require("@nem035/combs");

const res = combs(["a", 2, { value: "hi" }]);
/*
[
  ["a'],
  [2],
  [{ value: "hi' }],
  ["a', 2],
  ["a', { value: "hi' }],
  [2, { value: "hi' }],
  ["a', 2, { value: "hi' }]
]
*/

Installation

# npm
npm i @nem035/combs

# yarn
yarn add @nem035/combs

Licence

MIT