天天看點

js遞歸階乘 - 斐波那契數列

1~100之和

let xx = function sum(num){
	if(num<=1){
		return 1;
    }
    return num + sum(num - 1);
}
xx(100);
           

斐波那契數列

1 1 2 3 5 8 13 傳回目前位的數

let getCurrent = function aa(current){
	if(current <= 2) return 1;
	return aa(current - 1) + aa(current - 2);
}

getCurrent(6)
           

繼續閱讀