Skip to content

Instantly share code, notes, and snippets.

@phabee
Created October 5, 2020 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phabee/e0c3bf6f0a0dfdc34c5a23c0b63bec73 to your computer and use it in GitHub Desktop.
Save phabee/e0c3bf6f0a0dfdc34c5a23c0b63bec73 to your computer and use it in GitHub Desktop.
<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>
@phabee
Copy link
Author

phabee commented Oct 5, 2020

SImple JS-Demonstration to calculate a fibonacci-number using recursion using JavaScript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment