Created
October 28, 2013 18:21
-
-
Save martynchamberlin/7201899 to your computer and use it in GitHub Desktop.
Here's a bad, bad implementation of Fibonacci sequence. And yet it's the best I'm capable of coming up with by myself.
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
function fibonacci( n ) | |
{ | |
prev_1 = total = 0; | |
prev_2 = 1; | |
if ( n == 0 ) | |
return 0; | |
if ( n < 3 ) | |
return 1; | |
for ( var i = 0; i < n - 1; i++ ) | |
{ | |
prev_1 = prev_2; | |
prev_2 = total; | |
total = prev_1 + prev_2; | |
} | |
return total; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment