Finds all the combinations of given array.
A combination is a way of selecting members from a grouping, such that (unlike permutations) the order of selection does not matter. For example given three fruits, say an apple, an orange and a pear, there are three combinations of two that can be drawn from this set: an apple and a pear; an apple and an orange; or a pear and an orange.
A combination is a way of selecting members from a grouping, such that (unlike permutations) the order of selection does not matter. For example given three fruits, say an apple, an orange and a pear, there are three combinations of two that can be drawn from this set: an apple and a pear; an apple and an orange; or a pear and an orange.
Parameters:
| Name | Type | Description |
|---|---|---|
arr |
Array | Set of items. |
k |
Number | Size of each combination. |
- Source:
Returns:
Returns all combinations.
- Type
- Array
Example
var combinations = require('path-to-algorithms/src/' +
'combinatorics/combinations').combinations;
var result = combinations(['apple', 'orange', 'pear'], 2);
// [['apple', 'orange'],
// ['apple', 'pear'],
// ['orange', 'pear']]
console.log(result);