Skip to content

Instantly share code, notes, and snippets.

@juliekohl
Created May 19, 2023 13:33
Show Gist options
  • Save juliekohl/b4647d35007017776367130f912cdc66 to your computer and use it in GitHub Desktop.
Save juliekohl/b4647d35007017776367130f912cdc66 to your computer and use it in GitHub Desktop.
Fibonacci
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