Skip to content

Instantly share code, notes, and snippets.

@umcconnell
Last active August 20, 2019 14:52
Show Gist options
  • Save umcconnell/77ad603992282ef54f4633a3c3b8b25f to your computer and use it in GitHub Desktop.
Save umcconnell/77ad603992282ef54f4633a3c3b8b25f to your computer and use it in GitHub Desktop.
Recursive fibonacci sequence
/**
* 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