Created
January 15, 2018 12:42
-
-
Save dzautner/9409bf646a8a6e5e61b573b854c468f7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fibonacciResults = {} | |
function Fibonacci(n) { | |
if (!fibonacciResults[n]) { | |
fibonacciResults[n] = n <= 1 ? 1 : Fibonacci(n - 1) + Fibonacci(n - 2); | |
} | |
return fibonacciResults[n]; | |
} |
a bit clearer
const goldenRatio = 1.6180339887498948482045868;
fib = n => Math.floor(Math.pow(goldenRatio, n) - Math.pow(( 1 - goldenRatio ), n) / Math.sqrt(5))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
constant complexity / O(1)