I looked everywhere for efficient logic to get fibonacci series but all I could get was typical codes which hardly a newBie could understand so I simplified the whole in just few lines of code logic.
lets have a look:
The logic is as below:
//n is the number of limit for series
const getFibonacci = (n) => {
const result = [0,1];
for (let i = 1; i <= n; i++){
result.push(result[i - 1] + result[i]);
}
return result.join(`\n`)
}
getFibonacci(12)
Output :
0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987