Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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

combinations

find all combinations from array

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Combinations Build Status

Installation

npm install combinations

Usage

combinations(array[, min_output_array_size])
  • takes in an array, and outputs an array of arrays, containing all possible combinations of values in the original array.
  • combinations are of all sizes: all combinations of one element, and all combinations of 2 elements, and so on
  • minimum number of elements in a combination can be specified (min_output_array_size)
  • maximum number of elements in a combination can be also specified
  • if maximum combination value is bigger than array elements it will be overridden to the array length

Example

var combinations = require('combinations');
var myArray = ['red', 'orange', 'yellow', 'green'];

combinations(myArray); 

//Output:
//  [ [ 'red' ],                      [ 'orange' ],    
//    [ 'yellow' ],                   [ 'green' ],  
//    [ 'red', 'orange' ],            [ 'red', 'yellow' ],
//    [ 'red', 'green' ],             [ 'orange', 'yellow' ],
//    [ 'orange', 'green' ],          [ 'yellow', 'green' ],
//    [ 'red', 'orange', 'yellow' ],  [ 'red', 'orange', 'green' ],
//    [ 'red', 'yellow', 'green' ],   [ 'orange', 'yellow', 'green' ],
//    [ 'red', 'orange', 'yellow', 'green' ] ]

Example with a minimum array size

combinations(myArray, 2);

//Output:
//  [ [ 'red', 'orange' ],            [ 'red', 'yellow' ],
//    [ 'red', 'green' ],             [ 'orange', 'yellow' ],
//    [ 'orange', 'green' ],          [ 'yellow', 'green' ],
//    [ 'red', 'orange', 'yellow' ],  [ 'red', 'orange', 'green' ],
//    [ 'red', 'yellow', 'green' ],   [ 'orange', 'yellow', 'green' ],
//    [ 'red', 'orange', 'yellow', 'green' ] ]

Example with a minimum and maximum array size

combinations(myArray, 2, 3);

//Output:
//  [ [ 'red', 'orange' ],            [ 'red', 'yellow' ],
//    [ 'red', 'green' ],             [ 'orange', 'yellow' ],
//    [ 'orange', 'green' ],          [ 'yellow', 'green' ],
//    [ 'red', 'orange', 'yellow' ],  [ 'red', 'orange', 'green' ],
//    [ 'red', 'yellow', 'green' ],   [ 'orange', 'yellow', 'green' ] ]

Keywords

FAQs

Package last updated on 04 Nov 2019

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