DEV Community

Cover image for How to Calculate the Nth Fibonacci Number
Jon Randy 🎖️
Jon Randy 🎖️

Posted on

How to Calculate the Nth Fibonacci Number

Okay, lets dive straight into the code...

const fib = n =>
  Math.floor((((1 + 5**.5)/2)**n - ((1 - 5**.5)/2)**n)/5**.5)
Enter fullscreen mode Exit fullscreen mode

Explanation here.

Top comments (1)

Collapse
 
danielx17 profile image
Daniel Enesi

Wow.
High School Olympiad Math.
Well done!!!
🤩