Skip to content

Instantly share code, notes, and snippets.

@sdierauf
Last active August 29, 2015 14:09
Show Gist options
  • Save sdierauf/cc3c89b7d3b6bfe30d7e to your computer and use it in GitHub Desktop.
Save sdierauf/cc3c89b7d3b6bfe30d7e to your computer and use it in GitHub Desktop.
function softRecurse(func) {
setTimeout(func, 0);
}
var fibonacci = (function() {
var sum = 0;
return {
calc : function(x) {
sum = 0;
this.calcHelper(x);
},
calcHelper : function(x) {
if (x == 0) {
sum += 0;
} else if (x == 1) {
sum += 1;
} else {
softRecurse(this.calcHelper(x - 1));
softRecurse(this.calcHelper(x - 2));
}
},
val : function() {
return sum;
}
}
})();
fibonacci.calc(10)
fibonacci.val()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment