Created
August 22, 2018 13:19
-
-
Save oliverbth05/3889afbf8c33e81c515534548a482bca to your computer and use it in GitHub Desktop.
Javascript 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
function generateFibonacci(length){ | |
let sequence = [1]; | |
for(var i = 1; i <= length; i++){ | |
if (sequence.length === 1) { | |
sequence[i] = 1 | |
} | |
else{ | |
sequence[i] = sequence[i-1] + sequence[i - 2] | |
} | |
} | |
return sequence | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment