渡一——13-2 递归

递归有两个特征:

1.调用自身;2.找出口;

示例1

function test(n){
    if(n==1){
        console.trace();
        return 1;
    }
    return arguments.callee(n-1)*n;
}
test(4);

示例2

function mul(10) {
    if(n==1 || n==0){
        return 1;
    }
    return 10*mul(10-1);
}

function fb(n){
    if(n==1 || n==2){
        return 1;
    }
    return fb(n-1)+fb(n-2)
}
原文地址:https://www.cnblogs.com/lisa2544/p/15291643.html