1// declare the array starting with the first 2 values of the fibonacci sequence
2 let fibonacci = [0,1];
3
4 function listFibonacci(num) {
5 // starting at array index 1, and push current index + previous index to the array
6 for (let i = 1; i < num; i++) {
7 fibonacci.push(fibonacci[i] + fibonacci[i - 1]);
8 }
9 console.log(fibonacci);
10 }
11
12 listFibonacci(10);
13
1function Fibonacci(num){
2 var before = 0;
3 var actual = 1;
4 var next = 1;
5
6 for(let i = 0; i < num; i++){
7 console.log(next)
8 before = actual + next;
9 actual = next
10 next = before
11 }
12}
13
14Fibonacci(100);
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}
1function Fibonacci(valor){
2 var anterior = 0;
3 var atual = 1;
4 var proximo = 1;
5
6 for(let i = 0; i < valor; i++){
7 console.log(proximo)
8 anterior = atual + proximo;
9 atual = proximo
10 proximo = anterior
11 }
12}
13
14Fibonacci(100);
1var i;
2 var fib = []; // Initialize array!
3
4 fib[0] = 0;
5 fib[1] = 1;
6 for (i = 2; i <= 10; i++) {
7 // Next fibonacci number = previous + one before previous
8 // Translated to JavaScript:
9 fib[i] = fib[i - 2] + fib[i - 1];
10 console.log(fib[i]);
11 }
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}