1// number fibonnaci to array format
2function fibonacci(nums) {
3
4 let fib = [0, 1];
5 let data = [];
6
7 for(let i = 2; i <= nums; i++) {
8 fib[i] = fib[i - 1] + fib[i - 2];
9 data.push(fib[i]);
10 }
11
12 return data;
13}
1
2function fibonacci(num){
3 var num1=0;
4 var num2=1;
5 var sum;
6 var i=0;
7 for (i = 0; i < num; i++){
8 sum=num1+num2;
9 num1=num2;
10 num2=sum;
11 }
12 return num2;
13}
1const fibo = (n, memo = {}) => memo[n] || (n <= 2 ? 1 : (memo[n] = fibo(n - 1, memo) + fibo(n - 2, memo)));
2
3// Examples
4fibo(6); // 8