Skip to content

Instantly share code, notes, and snippets.

@navio
Created February 23, 2015 03:10
Show Gist options
  • Save navio/6a017fa1b4c3cc900dc5 to your computer and use it in GitHub Desktop.
Save navio/6a017fa1b4c3cc900dc5 to your computer and use it in GitHub Desktop.
Linear Fibonacci, Javascript
function runner(){
var a = 0;
var b = 1;
return function fibonacci(){
var c = a + b;
a = b; b = c;
print = function(){ console.log(c); };
return { c: c, print: print, };
};
}
var f = new runner();
for (var a = 0, myF = f(); a < 20; a++, myF = f() ){
myF.print();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment