You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
programming-examples/js/Math/Calculate the combination o...

26 lines
521 B
JavaScript

function product_Range(a,b) {
var prd = a,i = a;
while (i++< b) {
prd*=i;
}
return prd;
}
function combinations(n, r)
{
if (n==r)
{
return 1;
}
else
{
r=(r < n-r) ? n-r : r;
return product_Range(r+1, n)/product_Range(1,n-r);
}
}
console.log(combinations(6, 2));
console.log(combinations(5, 3));