Last active
July 30, 2020 22:44
-
-
Save martingaido/456d61501a2d0e0ce688a88b439e615f to your computer and use it in GitHub Desktop.
Function to create a Fibonacci sequence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Fibonacci Sequence */ | |
const fibonacci = (result: number[], len: number) => { | |
let n1: number = result[0], | |
n2: number = result[1], | |
next: number, | |
cnt: number = 2; | |
while (cnt < len) { | |
next = n1 + n2; | |
n1 = n2; | |
n2 = next; | |
result.push(next); | |
cnt++; | |
} | |
return result; | |
} | |
console.log(fibonacci([0, 1], 20)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment