Created
May 19, 2023 13:33
-
-
Save juliekohl/b4647d35007017776367130f912cdc66 to your computer and use it in GitHub Desktop.
Fibonacci
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
function fibonacci(n) { | |
const array = []; | |
if (n >= 1) { | |
array.push(0); | |
} | |
if (n >= 2) { | |
array.push(1); | |
} | |
for (let i = 2; i < n; i++){ | |
array.push(array[i - 1] + array[i - 2]); | |
} | |
return array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment