Combinations ![Build Status](https://camo.githubusercontent.com/0e0058c1d7f58f1615f7513f8887514c0b563655b2af5bb2a048169404adf1fd/68747470733a2f2f7472617669732d63692e6f72672f6a67616c6c656e32332f636f6d62696e6174696f6e732e7376673f6272616e63683d6d6173746572)
combinations(array, [min_output_array_size], [max])
- 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
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' ] ]