|
15 | 15 | } |
16 | 16 | } |
17 | 17 |
|
| 18 | + /** |
| 19 | + * A combination is a way of selecting members from a grouping, |
| 20 | + * such that (unlike permutations) the order of selection does not matter. |
| 21 | + * For example given three fruits, say an apple, an orange and a pear, |
| 22 | + * there are three combinations of two that can be drawn from this set: |
| 23 | + * an apple and a pear; an apple and an orange; or a pear and an orange. |
| 24 | + * |
| 25 | + * @example |
| 26 | + * |
| 27 | + * var combinations = require('path-to-algorithms/src/' + |
| 28 | + * 'combinatorics/combinations').combinations; |
| 29 | + * var result = combinations(['apple', 'orange', 'pear'], 2); |
| 30 | + * // [['apple', 'orange'], |
| 31 | + * // ['apple', 'pear'], |
| 32 | + * // ['orange', 'pear']] |
| 33 | + * console.log(result); |
| 34 | + * |
| 35 | + * @module combinatorics/combinations |
| 36 | + * @public |
| 37 | + * @param arr {Array} Set of items. |
| 38 | + * @param k {Number} Size of each combination. |
| 39 | + * @return {Array} Returns all combinations. |
| 40 | + */ |
18 | 41 | return function (arr, k) { |
19 | 42 | res = []; |
20 | 43 | combinations(arr, k, 0, 0, []); |
|
27 | 50 |
|
28 | 51 | exports.combinations = combinations; |
29 | 52 |
|
30 | | -}(typeof exports === 'undefined' ? window : exports)); |
| 53 | +}((typeof window === 'undefined') ? module.exports : window)); |
0 commit comments