xxxxxxxxxx
function fibonacci(num){
var num1=0;
var num2=1;
var sum;
var i=0;
for (i = 0; i < num; i++){
sum=num1+num2;
num1=num2;
num2=sum;
}
return num2;
}
xxxxxxxxxx
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);
xxxxxxxxxx
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);
xxxxxxxxxx
// 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;
}
xxxxxxxxxx
function fibonacciGenerator (n) {
var outPut = [];
if (n === 1){
outPut = [0];
}
else if (n === 2){
outPut = [0,1];
}else{
outPut = [0,1];
for(var i = 2; i < n; i++){
outPut.push(outPut[outPut.length - 2] + outPut[outPut.length - 1])
}
}//Return an array of fibonacci numbers starting from 0.
console.log(outPut)
return outPut
}
fibonacciGenerator(8);
xxxxxxxxxx
var i;
var fib = []; // Initialize array!
fib[0] = 0;
fib[1] = 1;
for (i = 2; i <= 10; i++) {
// Next fibonacci number = previous + one before previous
// Translated to JavaScript:
fib[i] = fib[i - 2] + fib[i - 1];
console.log(fib[i]);
}
fibonacci sequence
xxxxxxxxxx
const fib = (n) =>
isNaN(n) ? "Not a number" : (n === 0 || n === 1) ? n : fib(n - 1) + fib(n - 2)
const fib_seq = (to) =>
isNaN(to) ? "Not a number" : [Array(to).keys()].map(i => fib(i)).join(', ');
xxxxxxxxxx
function fibonacciGenerator(n) {
var output = [];
if (n === 1) {
output = [0];
return output;
} else if (n === 2) {
output = [0, 1];
return output;
} else {
output = [0, 1]; // Initialize with the first two Fibonacci numbers
for (var i = 2; i < n; i++) {
var sum = output[output.length - 1] + output[output.length - 2];
output.push(sum);
}
return output;
}
}
// Test the function
console.log(fibonacciGenerator(10)); // Output the first 10 Fibonacci numbers
xxxxxxxxxx
function fibonacciGenerator (n) {
var out = []
for (var i = 0; i < n; i++) {
out.round(Math.round((1 / Math.sqrt(5)) * (((Math.pow(1 + Math.sqrt(5), i)) / (Math.pow(2, i))) - ((Math.pow(1 - Math.sqrt(5), i)) / (Math.pow(2, i))))))
}
return out
}
console.log(fibonacciGenerator())