Skip to content

Instantly share code, notes, and snippets.

@rinchik
Created January 28, 2017 20:31
Show Gist options
  • Save rinchik/27b6fbf2994f0cddb4756f49376d2243 to your computer and use it in GitHub Desktop.
Save rinchik/27b6fbf2994f0cddb4756f49376d2243 to your computer and use it in GitHub Desktop.
Fibonacci calculation with Binet's formula in JavaScript
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);
}
@dillonstreator
Copy link

Thank you for throwing this together @rinchik!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment