几个简单递归js 实现
斐波那契数列:(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);}
斐波那契数列:(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);}