Skip to content

Instantly share code, notes, and snippets.

@reyou
Created May 24, 2018 02:17
Show Gist options
  • Save reyou/9ea4110c831416cebdc488604383dd9a to your computer and use it in GitHub Desktop.
Save reyou/9ea4110c831416cebdc488604383dd9a to your computer and use it in GitHub Desktop.
// find nth fibonacci both recursive and iterative
// 0 1 1 2 3 5 8 13 21
// 0 1 2 3 4 5 6 7 8
function fibo(nth) {
// return statement
if (nth === 0) {
return 0;
}
if (nth === 1) {
return 1;
}
return fibo(nth - 1) + fibo(nth - 2);
}
console.log(fibo(6));
console.log(fibo(7));
console.log(fibo(8));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment