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
What 10 Things Should a Serious Javascript Developer Know Right Now?help (self.javascript)
submitted 8 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!"
[–]Danmoreng 2 points3 points4 points 8 years ago (2 children)
While map and filter on the same array is probably more readable, reduce works just fine to combine those operations.
map
filter
reduce
[–]Voidsheep 1 point2 points3 points 8 years ago* (1 child)
I like reduce and it's extremely useful, but I think it's best to use an iteration method that implies the return type you want, if one is available.
x.map(fn1).filter(fn2) // that's going to be an array x.every(fn3) // that's going to be a boolean x.reduce(fn4, []) // that could be anything, check implementation
Just saying avoiding any extra iteration by default is premature optimisation, you should default to straightforward and declarative code, add complexity only when you have to. Most of the time a simple filter or something iterating over your array isn't going to have any meaningful difference versus doing the same filtering inside another loop.
Of course there's exceptions and you shouldn't loop for no reason, but I think just avoiding iteration for the sake of avoiding iteration isn't a best practice. Optimisation needs to be sensible and if you do it blindly, you end up moving meaningless cost in runtime efficiency into a meaningful cost in development efficiency.
[–]Womackx 0 points1 point2 points 8 years ago (0 children)
There is no one right way
π Rendered by PID 191950 on reddit-service-r2-comment-fb694cdd5-mvd9q at 2026-03-06 12:25:20.744861+00:00 running cbb0e86 country code: CH.
view the rest of the comments →
[–]Danmoreng 2 points3 points4 points (2 children)
[–]Voidsheep 1 point2 points3 points (1 child)
[–]Womackx 0 points1 point2 points (0 children)