标签:
计算阶乘的函数
function factorial(n){ var product = 1; while(n>1){ product *= n; n--; } return product; } factorial(4) function factorial2(n) { var i, product = 1; for (i = 2; i <= n; i++) { product *= i; } return product; } factorial2(2)
绝对值函数
function abs(x) {
if (x >= 0) {
return x;
} else {
return - x;
}
}
abs(-2)
标签:
原文地址:http://www.cnblogs.com/ron123/p/5398426.html