May I suggest a recursive version with a cache ? I don't know if this is a huge improvement in this case but 🤷
function fibonacci (index) { cache = [0, 1] function eval_fib_rank (rank) { return rank in cache ? cache[rank] : cache[rank] = eval_fib_rank(rank - 1) + eval_fib_rank(rank - 2) } eval_fib_rank(index); return cache; } console.log(fibonacci (9))
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
May I suggest a recursive version with a cache ? I don't know if this is a huge improvement in this case but 🤷