Skip to content

Instantly share code, notes, and snippets.

@dev-sampsonorson
Last active February 12, 2022 15:26
Show Gist options
  • Save dev-sampsonorson/6a93e17eaed82cd58da6c65e3692f148 to your computer and use it in GitHub Desktop.
Save dev-sampsonorson/6a93e17eaed82cd58da6c65e3692f148 to your computer and use it in GitHub Desktop.
Recursive implementation of fibonacci (non-optimized)
const input1 = 7; // index
const input2 = 2; // index
const input3 = 3; // index
const fib = (index) => {
if ((index === 0) || (index === 1))
return index;
return fib(index - 2) + fib(index - 1);
}
console.log(fib(input1));
console.log(fib(input2));
console.log(fib(input3));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment