Pages

Sunday, December 26, 2010

Factorial

/**
 * This function provide factorial service
 * 
 * @author  : irfanudin ridho
 * @email   : irfan.ub@gmail.com
 * @date    : December 26, 2010
 * @version : 1.0
 *
 * @param n number a factor of the factorial
 * @return sum total summing of the factor
 */

function factorial(n){
    if (n==0) return 1;
    else if (n<0) return 'invalid factor';
    var sum = 1;
    for(i=n;i>0;i--){
        sum = sum * i;
    }
    return sum;
}

No comments:

Post a Comment