Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<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