Last active
August 29, 2015 14:09
-
-
Save sdierauf/cc3c89b7d3b6bfe30d7e to your computer and use it in GitHub Desktop.
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 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