fibonacci series program in javascript code example
Example 1: fibonacci javascript
function Fibonacci(num){
var before = 0;
var actual = 1;
var next = 1;
for(let i = 0; i < num; i++){
console.log(next)
before = actual + next;
actual = next
next = before
}
}
Fibonacci(100);
Example 2: fibonacci javascript
function Fibonacci(valor){
var anterior = 0;
var atual = 1;
var proximo = 1;
for(let i = 0; i < valor; i++){
console.log(proximo)
anterior = atual + proximo;
atual = proximo
proximo = anterior
}
}
Fibonacci(100);
Example 3: javascript fibonacci series
const fibo = (n, memo = {}) => memo[n] || (n <= 2 ? 1 : (memo[n] = fibo(n - 1, memo) + fibo(n - 2, memo)));
fibo(6);