Last active
August 20, 2019 14:52
-
-
Save umcconnell/77ad603992282ef54f4633a3c3b8b25f to your computer and use it in GitHub Desktop.
Recursive 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
/** | |
* Generate the fibonaccie sequence recursively | |
* @param {number} num amount of recursion | |
* @returns {array} fibonacci sequence | |
*/ | |
let fib = num => { | |
if (num == 1) return [1]; | |
else { | |
let prev = fib(num - 1); | |
return prev.concat((prev[prev.length - 2] || 0) + prev[prev.length - 1]) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment