Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Fibonacci numbers for n terms

const getFibonacciNumbers = (n) => {
	let n1 = 0;
	let n2 = 1;
	let nextNumber;
	let fibonacciNumbers = [];

	let i = 1;
	while (i <= n) {
		fibonacciNumbers.push(n1);
		nextNumber = n1 + n2;
		n1 = n2;
		n2 = nextNumber;
	}

	return fibonacciNumbers;
};
 
PREVIOUS NEXT
Tagged: #Fibonacci #numbers #terms
ADD COMMENT
Topic
Name
9+3 =