Maths Factorial Function

Recursive function:

function factorial(n) {
    if (n == 0) {
        return 1;
    }
    return n * factorial(n - 1); 
}
[1]

Non-recursive function:

function factorial(n) {
var product=1;
    if (n == 0) {
        product = 1;
    }
for (x=n; x>0; x--)
{
product *= x;
}
return product;
}

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License