Fibonnacci

Date: 2018-08-17
const round = Math.round, pow = Math.pow, sqrt = Math.sqrt
const sqrt5 = sqrt(5), phi = (1 + sqrt(5)) / 2
const fibonacci1 = (n) => round((pow(phi, n) -  pow(1-phi, n)) / sqrt5)

function fibonacci2(n) {
	return Math.round((Math.pow((1 + Math.sqrt(5)) / 2, n) -  Math.pow(-2 / (1 + Math.sqrt(5)), n)) /  Math.sqrt(5));
}

function fib(a, b, n) { 
	if(n) {
		return fib(b, a + b, n - 1); 
	} else {
		return a;
	}
}

const fibonacci3 = (n) => {
	return fib(0, 1, n);
}

 

12180cookie-checkFibonnacci