1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.combinationsNumber = combinationsNumber;
|
7 |
|
8 | var _number = require("../../utils/number.js");
|
9 |
|
10 | var _product = require("../../utils/product.js");
|
11 |
|
12 | function combinationsNumber(n, k) {
|
13 | if (!(0, _number.isInteger)(n) || n < 0) {
|
14 | throw new TypeError('Positive integer value expected in function combinations');
|
15 | }
|
16 |
|
17 | if (!(0, _number.isInteger)(k) || k < 0) {
|
18 | throw new TypeError('Positive integer value expected in function combinations');
|
19 | }
|
20 |
|
21 | if (k > n) {
|
22 | throw new TypeError('k must be less than or equal to n');
|
23 | }
|
24 |
|
25 | var nMinusk = n - k;
|
26 | var prodrange;
|
27 |
|
28 | if (k < nMinusk) {
|
29 | prodrange = (0, _product.product)(nMinusk + 1, n);
|
30 | return prodrange / (0, _product.product)(1, k);
|
31 | }
|
32 |
|
33 | prodrange = (0, _product.product)(k + 1, n);
|
34 | return prodrange / (0, _product.product)(1, nMinusk);
|
35 | }
|
36 |
|
37 | combinationsNumber.signature = 'number, number'; |
\ | No newline at end of file |