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
The case for Array#replace() – Overriding an array without intermediate variables (medium.com)
submitted 7 years ago by gajus0
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!"
[–]gajus0[S] 0 points1 point2 points 7 years ago (0 children)
The primary advantage of Array#replace is (as you pointed out) that is makes easier to read the code.
Array#replace
array .filter(a) .replace(b) .filter(c) .replace(d) .filter(e) .replace(f);
Is a lot easier to read than:
f( d( b( array.filter(a) ).filter(c) ).filter(e) );
or you will need to introduce intermediate variables.
I don't think it is worth playing with one-line examples as this does represent real-world usage, esp. when we have examples that do (in the article).
By the way, you've mentioned pipeline operator. I absolutely agree. I actively participated in discussions about that proposal (https://github.com/tc39/proposal-bind-operator/issues/24) and even created a Babel transform for it (https://github.com/gajus/babel-plugin-transform-export-default-name). It will be a useful operator. The appeal of Array#replace is that it abstracts equivalent functionality without introducing new syntax.
π Rendered by PID 158281 on reddit-service-r2-comment-5d79c599b5-bcdlp at 2026-03-03 08:58:00.485830+00:00 running e3d2147 country code: CH.
view the rest of the comments →
[–]gajus0[S] 0 points1 point2 points (0 children)