1var fib = function(n) {
2 if (n === 1) {
3 return [0, 1];
4 } else {
5 var arr = fib(n - 1);
6 arr.push(arr[arr.length - 1] + arr[arr.length - 2]);
7 return arr;
8 }
9};
10
11console.log(fib(8));
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