August 2024
Intermediate to advanced
516 pages
11h 47m
English
The Fibonacci sequence is a mathematical sequence of numbers that goes like this until infinity:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55…
This sequence begins with the numbers 0 and 1, and each subsequent number is the sum of the previous two numbers of the sequence. For example, the number 55 was computed because it is the sum of the previous two numbers, which are 21 and 34.
The following JavaScript function returns the Nth number in the Fibonacci sequence. For example, if we pass the number 10 to the function, it will return 55, as 55 is the tenth number in the series. (The 0 is considered the 0th number in the series.)
| | function fib(n) { |
| | if (n === 0 || n === 1) { |
| | return n; |
| | } |
| | |
| | return fib(n - 2) + fib(n ... |
Read now
Unlock full access