Skip to content

Instantly share code, notes, and snippets.

@danlourenco
Created August 17, 2016 15:34
Show Gist options
  • Save danlourenco/c943b684e264ff9bd20943219259c764 to your computer and use it in GitHub Desktop.
Save danlourenco/c943b684e264ff9bd20943219259c764 to your computer and use it in GitHub Desktop.
Generates fibonacci sequence recursively
function fibonacci(n) {
if (n <= 2) { // base case
return 1;
}
else {
return fibonacci(n - 1) + fibonacci(n - 2);
}
}
fibonacci(8) // 21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment