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

ml-combinations

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ml-combinations

Generate all possible unordered samples of size m, without replacement, from a set of n objects

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
376
increased by45.74%
Maintainers
1
Weekly downloads
 
Created
Source

combinations

NPM version build status David deps npm download

Generate all possible unordered samples of size m, without replacement, from a set of n objects

Very low memory footprint even if the number of combinations to generate is high.

Installation

$ npm install ml-combinations

Usage

// the package exports a generator function
const combinations = require('ml-combinations');
const options = {mode: 'index'};

// the generator function returns an iterator
var gen = combinations(2, 4, options);

// You can loop throw the iterator
for(let combination of gen) {
    console.log(combination);
}

// Or use destructuring
console.log([...gen]); // [ [ 3, 2 ], [ 0, 2 ], [ 1, 2 ], [ 1, 2 ], [ 0, 2 ], [ 0, 1 ] ]

// Use mask mode instead of index mode (index mode is the default)
options.mode = 'mask';
gen = combinations(2, 4, options);
console.log([...gen]); // [ [ 0, 0, 1, 1 ][ 1, 0, 0, 1 ],[ 0, 1, 0, 1 ],[ 0, 1, 1, 0 ],[ 1, 0, 1, 0 ],[ 1, 1, 0, 0 ] ]

References

Phillip J Chase, `Algorithm 382: Combinations of M out of N Objects [G6]', Communications of the Association for Computing Machinery 13:6:368 (1970). To the article

License

MIT

Keywords

FAQs

Package last updated on 20 Jul 2016

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