Skip to content

Instantly share code, notes, and snippets.

@saneef
Last active January 19, 2016 10:21
Show Gist options
  • Save saneef/28a0b24cdff849d62607 to your computer and use it in GitHub Desktop.
Save saneef/28a0b24cdff849d62607 to your computer and use it in GitHub Desktop.
JavaScript function to get N-th Fibnocci number
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