Using _.trampoline for recursive functions
http://runnable.com/U5xjrghR-NEC1pOa/_-trampoline-example-for-node-js
Based on http://raganwald.com/2013/03/28/trampolines-in-javascript.html
function factorial(n) {
var _factorial = function myself(acc, n) {
return n ? function() {
return myself(acc * n, n - 1);
} : function() {
return _.done(acc);
}
}
return _.trampoline(_factorial, 1, n);
}
factorial(32768)
// Infinity
Written by Raine Virta
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Underscore
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#