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!!!
๐Ÿคฉ