递归

//斐波那契数列:(i最好不要超过40,要不然浏览器也可能hold不住)

function f(i){return i<3?1:f(i-1)+f(i-2);}

//求n! 即,1×2×3×4×5×······×n

function n(i){return i<2?1:i*n(i-1);}

//求1+2+···+n

function p(i){return i<2?1:i+p(i-1);}

//js递归调用

function fact(num) {
if (num <= 1) {
return 1;
} else {
return num * fact(num - 1);
}
}

 

posted @ 2016-04-26 21:22  待繁华落尽  阅读(121)  评论(0编辑  收藏  举报