Created
March 30, 2019 11:20
-
-
Save jimmy89Li/66249a3b9dfe8f36d317ad169e9e05dd to your computer and use it in GitHub Desktop.
JavaScript fibonacci function
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
function fib(num) { | |
if(num <= 1) { | |
return 1; | |
} else { | |
return fib(num - 1) + fib(num - 2); | |
} | |
} | |
console.log(fib(4)); // 5 | |
console.log(fib(10)); // 89 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment