diff --git a/src/index.js b/src/index.js index c1c407d..e76dc1e 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,28 @@ -const fibonacci = (n) => { - + const fibonacci = (n) => { + let arr = []; + if(n === 0) + return 0; + if(n === 1) { + arr.push(1) + return arr; + } + + + if(n === 2) { + arr.push(1,1) + return arr; + } + + if(n > 2) { + arr.push(1,1) + let fibonacciNumber = 0 + + for(let index = 1; index <= n-2; index++) { + fibonacciNumber = arr[index] + arr[index - 1] + arr.push(fibonacciNumber) + } + return arr; + } } - module.exports = fibonacci; \ No newline at end of file