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.
|
function fallingFactorial(n, k)
|
|
{
|
|
var i = (n - k + 1),
|
|
r = 1;
|
|
if (n < 0)
|
|
{
|
|
throw new Error("n must be positive.");
|
|
}
|
|
if (k > n)
|
|
{
|
|
throw new Error("k cannot be greater than n.");
|
|
}
|
|
while (i <= n)
|
|
{
|
|
r *= i++;
|
|
}
|
|
return r;
|
|
}
|
|
console.log(fallingFactorial(10, 2));
|