What is a fibonacci: The last number will be the summation of the immediate two first number.
Rule
Fn = Fn-2 + Fn-1
Now calculation of fibonacci number for n = 5
F5 = F3 + F4
F3 = F1 + F2
F4 = F2 + F3
In fibonacci series 0 & 1 are the fibonacci for 1 & 2. For that reason
F1 = 0
F2 = 1
We know from the previous calculation
F5 = F3 + F4
F5 = F1 + F2 + F4
F5 = F1 + F2 + F2 + F3
F5 = F1 + F2 + F2 + F1 + F2
F5 = 0 + 1 + 1 + 0 + 1
F5 = 3
The 5th number fibonacci is 3
To compile TypeScript to javascript, run the command.
tsc
Run the main js file
node main.js