Skip to content

Instantly share code, notes, and snippets.

View jerrygreen's full-sized avatar

Jerry Green jerrygreen

View GitHub Profile
@jerrygreen
jerrygreen / fib.js
Created July 2, 2021 15:20 — forked from beastaugh/fib.js
Calculate Fibonacci numbers in JavaScript
/**
* The Fibonacci numbers in JavaScript.
*
* A cached solution with O(1) lookup for previously-calculated terms and O(N)
* lookup for uncalculated ones.
*
* Because numbers in JavaScript are 64bit, the largest available number is
* 1.7976931348623157e+308. The 1476th term is the last that can be calculated.
* If a later term is requested, the function will return Infinity.
*