javascript generate fibonacci numbers code example
Example 1: 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;
}
Example 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));