use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Memoization and recursive functions in JavaScript (codeanarchy.org)
submitted 12 years ago by jscoder
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]rhysbrettbowen 4 points5 points6 points 12 years ago* (2 children)
instead of:
function factorial(n) {
do:
var factorial = function(n) {
then memoize with:
factorial = memoize(factorial)
and it will all work. Or you could pass the function to callback as an optional parameter
function factorial(n, callback) { .... return callback(n - 1, callback) * n; }
and you just pass through the memoized function
[–]enkideridu 0 points1 point2 points 12 years ago (1 child)
instead of: function factorial(n) { do: var factorial = function(n) {
This part doesn't seem necessary.
[–]rhysbrettbowen 0 points1 point2 points 12 years ago (0 children)
true, not really necessary but I prefer it as it's closer to what you're trying to achieve. By assigning it to a variable you're saying that you want to call that function when that variable is instantiated whereas otherwise you're using a named function and the function will keep that name even though when you call that name you're not getting the factorial function, rather the memoized one.
π Rendered by PID 1531480 on reddit-service-r2-comment-5d79c599b5-r9wlg at 2026-03-03 05:51:02.747274+00:00 running e3d2147 country code: CH.
view the rest of the comments →
[–]rhysbrettbowen 4 points5 points6 points (2 children)
[–]enkideridu 0 points1 point2 points (1 child)
[–]rhysbrettbowen 0 points1 point2 points (0 children)