Created
May 24, 2018 02:17
-
-
Save reyou/9ea4110c831416cebdc488604383dd9a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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