Skip to content

Commit 1c8e975

Browse files
author
AndreyGeonya
committed
combinations jsdoc
1 parent 31cf88a commit 1c8e975

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/combinatorics/cartesianproduct.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
* @return {Array} Cartesian product of provided sets.
2424
*
2525
* @example
26-
* var product = require('../src/combinatorics/cartesianproduct')
27-
* .cartesianProduct;
26+
* var product = require('path-to-algorithms/src/combinatorics/' +
27+
* 'cartesianproduct').cartesianProduct;
2828
* var result = product([[1, 2, 3], [3, 2, 1]]);
2929
* // [ [ 1, 3 ],
3030
* // [ 1, 2 ],

src/combinatorics/combinations.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,29 @@
1515
}
1616
}
1717

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+
*/
1841
return function (arr, k) {
1942
res = [];
2043
combinations(arr, k, 0, 0, []);
@@ -27,4 +50,4 @@
2750

2851
exports.combinations = combinations;
2952

30-
}(typeof exports === 'undefined' ? window : exports));
53+
}((typeof window === 'undefined') ? module.exports : window));

0 commit comments

Comments
 (0)