const cache = []
function fi(n) {
if (cache[n] !== undefined) {
return cache[n]
}
if (n == 1 || n == 2) {
cache[n] = 1
return 1
}
cache.push(fi(n-2) + fi(n-1))
return cache[n]
}
console.log(fi(5)) // 5
複製代碼