function fiboAdd(len){
var res = []
for(var i = 0; i < len; i++){
if( i === 0 || i === 1){
res.push(1)
}else {
res.push((res[i-1]+res[i-2]))
}
}
}
return res
}
function fibonacci (n) {
if (n==1 || n==2) {
return 1
}
return fibonacci(n-1)+fibonacci(n-2)
}
console.log(fibonacci(3))
const Fib = (n, prev = 1, next = 1) => {
if (n < 2) {
return next
}
return Fib(n - 1, next, prev + next)
}
console.log(Fib(3))
网友评论