New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

allcombinations

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

allcombinations

returns a list of all possible combinations / permutations of an array of items

  • 1.1.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

allcombinations Build Status

Calculates on demand all possible combinations of the elements of a given array. For this to be efficient a ES2015 generator is utilized.

The number of possible combinations gets really big really fast (e.g. an array of 5 elements already has 120 possible permutations!). Thus it is not realistic (or even possible) to precalculate the complete range of permutations and subsequently return it. (memory and cpu consumption would be absolutely terrible)

With this generator approach the combinations are computed lazily which results in a minimal memory footprint.

Installation

npm i allcombinations --save

Usage

const allcombinations = require('allcombinations');

let allCombinationsGenerator = allcombinations([1, 2, 3]);

for (var combination of allCombinationsGenerator) {
    console.log(combination);
}

// [1, 2, 3]
// [1, 3, 2]
// [2, 1, 3]
// [2, 3, 1]
// [3, 1, 2]
// [3, 2, 1]

Keywords

FAQs

Package last updated on 21 Jan 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc