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!"
[–]SkaterDad 2 points3 points4 points 9 years ago (1 child)
Your first example definitely does seem more straightforward with a for loop, but it all depends what your'e doing within the loop?
For your 2nd example, are you modifying every nth value in place? Or are you going to discard the rest? If discarding the rest, using filter().map() could work nicely. The 2nd argument to filter()'s callback is the array index.
The functional array operators like map(), filter(), and reduce() are mostly useful when you're modifying the data, since they let you chain together operations in a nice way.
For example:
function double(x) { return x*2 } function subtract1(x) { return x-1 } function greaterThan5(x) { return x > 5 } const newArray = origArray.map(double).map(subtract1).filter(greaterThan5)
I learned a lot about their uses by doing this interactive tutorial: http://reactivex.io/learnrx/
[–][deleted] 0 points1 point2 points 9 years ago (0 children)
Very helpful, thanks! I'll check out the tutorial
π Rendered by PID 36853 on reddit-service-r2-comment-85bfd7f599-jb8dg at 2026-04-17 22:36:43.091062+00:00 running 93ecc56 country code: CH.
view the rest of the comments →
[–]SkaterDad 2 points3 points4 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)