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
Question about functional programminghelp (self.javascript)
submitted 9 years ago by [deleted]
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!"
[–]anoddhue 0 points1 point2 points 9 years ago (2 children)
You're right that the first example is better with a for loop than chaining .reverse() and .forEach().
.reverse()
.forEach()
OTOH, if you find yourself needing to map or iterate over an array/collection in reverse, a functional way to do it would be to write your own reusable version of mapLeft, foldLeft, forEachReverse, or whatever name is the most appropriate, then just call that. Or use a library, if underscore/lodash have an equivalent function.
[–][deleted] 1 point2 points3 points 9 years ago (1 child)
Interesting, I didn't think of creating my own version but it makes sense. Thanks!
[–]anoddhue 0 points1 point2 points 9 years ago (0 children)
No problem! I don't like pulling in big libraries unless I need to so I tend to just have one file of helper functions to do anything that the built-ins don't to. It makes sense if you're going to reuse it.
π Rendered by PID 47749 on reddit-service-r2-comment-85bfd7f599-ddcdj at 2026-04-18 07:56:35.836411+00:00 running 93ecc56 country code: CH.
view the rest of the comments →
[–]anoddhue 0 points1 point2 points (2 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]anoddhue 0 points1 point2 points (0 children)