how to generate a fibonacci sequence in javascript fibonacci counter in typescript

The solution for “how to generate a fibonacci sequence in javascript fibonacci counter in typescript” can be found here. The following code will assist you in solving the problem.

// declare the array starting with the first 2 values of the fibonacci sequence
let fibonacci = [0,1];

function listFibonacci(num) {
// starting at array index 1, and push current index + previous index to the array
for (let i = 1; i < num; i++) { fibonacci.push(fibonacci[i] + fibonacci[i - 1]); } console.log(fibonacci); } listFibonacci(10); '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));

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

0
inline scripts encapsulated in