Created
October 5, 2020 05:29
-
-
Save phabee/e0c3bf6f0a0dfdc34c5a23c0b63bec73 to your computer and use it in GitHub Desktop.
This file contains 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
<script type = "text/javascript"> | |
function fibonacci(n) | |
{ | |
if (n > 2) | |
return fibonacci(n-2) + fibonacci(n-1); | |
if (n == 2 || n == 1) | |
return 1; | |
return 0; | |
} | |
var start = new Date(); | |
var result = fibonacci(30) | |
var time = new Date() - start; | |
document.write("Fibonacci(30): "+result+"<br>"); | |
document.write("Duration: "+time+"ms <br>"); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SImple JS-Demonstration to calculate a fibonacci-number using recursion using JavaScript.