javascript recursive function for fibonacci series
// number fibonnaci to array format
function fibonacci(nums) {
let fib = [0, 1];
let data = [];
for(let i = 2; i <= nums; i++) {
fib[i] = fib[i - 1] + fib[i - 2];
data.push(fib[i]);
}
return data;
}var fib = function(n) {
if (n === 1) {
return [0, 1];
} else {
var arr = fib(n - 1);
arr.push(arr[arr.length - 1] + arr[arr.length - 2]);
return arr;
}
};
console.log(fib(2));Enter the number of terms: 12
0
1
1
2
3
Also in JavaScript:
- lodash find object in array
- user agent chrome
- javascript random number
- how to get session javascript ws3schools
- angular x social login
- javascript transfer to another page
- setinterval vs settimeout in javascript\
- how to change checkbox state in jquery
- JavaScript how do you create a screen pressable button in 10 lines?
- stopper un intervalle javascript
- cut text if too long javascript
- react native list view
- open bytes in new tab angular
- jquery each has class
- nodejs hello world
- create eventlistener to close webpage js
- remove disabled attribute javascript
- nextjs svg npm
- js loop through associative array
- how to get a value into a react component
- codeigniter csrf token ajax
- setting property to method in child class javascript
- interpolation react
- i18n angular