Answers for "javascript fibonaci"

5

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);
Posted by: Guest on December-14-2020
3

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);
Posted by: Guest on December-14-2020
0

fibonacci best performance javascript

// A sequência começa com 0 e 1, depois,
// os números subsequentes são compostos
// pela soma dos dois números anteriores
// da sequência. Daí:
// (x - 2) + (x - 1) = próximo número da sequência
function fibonacci(n) {
	const list = [0, 1];
	for (let x = 2; x < n + 1; x += 1) {
		list.push(list[x - 2] + list[x - 1]);
	}
	return list[n];
}

console.log(fibonacci(4));
Posted by: Guest on May-28-2020
0

fibonacci javascript

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; 
}
Posted by: Guest on December-09-2020
0

fibonacci sums javascript

// Implement a method that finds the sum of the first n
// fibonacci numbers recursively. Assume n > 0

function fibsSum(n) {
    if ( n === 1 ) {
        return 1;
    }
    if (n === 2 ) {
        return 2;
    }
    let sum = fibsSum(n-1) + n;
    return sum;
}
Posted by: Guest on October-24-2020
-2

fibonacci counter in typescript

'use strict';

let fibonacci: number[] = [0, 1];

function listFibonacci(num: number) {
  for (let i: number = 2; i < num; i++) {
    fibonacci[i] = fibonacci[i - 2] + fibonacci[i - 1];
  }
  return fibonacci;
}
console.log(listFibonacci(10));
Posted by: Guest on December-09-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language