combinatorics/combinations

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.
Source:
Parameters:
Name Type Description
arr Array Set of items.
k Number Size of each combination.
Returns:
Type:
Array
Returns all combinations.
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);