Created
January 28, 2017 20:31
-
-
Save rinchik/27b6fbf2994f0cddb4756f49376d2243 to your computer and use it in GitHub Desktop.
Fibonacci calculation with Binet's formula in JavaScript
This file contains 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
function fibonacci(number) { | |
var sqRootOf5 = Math.sqrt(5); | |
var Phi = (1+sqRootOf5)/2; | |
var phi = (1-sqRootOf5)/2 | |
return Math.round((Math.pow(Phi, number) - Math.pow(phi, number)) / sqRootOf5); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for throwing this together @rinchik!