Skip to content

Instantly share code, notes, and snippets.

@martynchamberlin
Created October 28, 2013 18:21
Show Gist options
  • Save martynchamberlin/7201899 to your computer and use it in GitHub Desktop.
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.
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