programming-examples/js/Math/Evaluate binomial coefficients.js
2019-11-15 12:59:38 +01:00

11 lines
322 B
JavaScript

function binomial(n, k) {
if ((typeof n !== 'number') || (typeof k !== 'number'))
return false;
var coeff = 1;
for (var x = n-k+1; x <= n; x++) coeff *= x;
for (x = 1; x <= k; x++) coeff /= x;
return coeff;
}
console.log(binomial(8,3));
console.log(binomial(10,2));