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)
// InfinityWritten by Raine Virta
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Underscore
Authors
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#