UNPKG

@nexys/math-ts

Version:

[![npm version](https://badge.fury.io/js/%40nexys%2Fmath-ts.svg)](https://www.npmjs.com/package/@nexys/math-ts) [![TavisCI](https://travis-ci.com/Nexysweb/tableau-wdc-react.svg?branch=master)](https://travis-ci.com/github/Nexysweb/math-ts) [![Deployment](

33 lines (32 loc) 962 B
"use strict"; var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result["default"] = mod; return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const U = __importStar(require("./utils")); exports.coefficientR = (n, k) => { if (n < 1) { throw Error('n>=1'); } if (k < 0) { throw Error('k>=0'); } if (k === 0 || k === n) { return 1; } if (k === 1) { return n; } if (k > n) { return -1; } if (k > U.divWoRest(n, 2) + 1) { return exports.coefficientR(n, k - U.divWoRest(n, 2) - 1); } return exports.coefficientR(n - 1, k - 1) + exports.coefficientR(n - 1, k); }; exports.coefficient = (n, k) => U.factorial(n) / (U.factorial(k) * U.factorial(n - k));