Last active
January 19, 2016 10:21
-
-
Save saneef/28a0b24cdff849d62607 to your computer and use it in GitHub Desktop.
JavaScript function to get N-th Fibnocci number
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 getNthFibnocci(n) { | |
// Based on Binets formula http://www.maths.surrey.ac.uk/hosted-sites/R.Knott/Fibonacci/fibFormula.html#formula | |
return Math.round((1 / Math.sqrt(5)) * ((Math.pow((1 + Math.sqrt(5)) / 2, n) - (Math.pow((1 - Math.sqrt(5)) / 2, n))))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment