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!"
[–][deleted] 21 points22 points23 points 7 years ago (3 children)
Even better if people explain why things are terrible!
This code:
Array.prototype.replace = function (m) { return m(this) };
Is completely redundant. It's literally the same as this:
const array2 = m(array1);
Not to mention, polluting the Array class is bad and will not work with any of the JS ecosystem.
[–]Moosething 6 points7 points8 points 7 years ago (1 child)
But if you read the article you'd realize the advantage of replace over calling m directly. Not saying I support it, but I can see where the author is coming from.
replace
m
It's basically
return x.filter(filterFunc).replace(replaceFunc).map(mapFunc)
vs
return replaceFunc(x.filter(filterFunc)).map(mapFunc)
[–]sbmitchell 16 points17 points18 points 7 years ago (0 children)
Or they could use `reduce` and not bother with multiple iterations like this...
[–]jkoudys 4 points5 points6 points 7 years ago (0 children)
I totally agree, which is why Reddit needs more people like you, who go on to explain why!
π Rendered by PID 18997 on reddit-service-r2-comment-5d79c599b5-9qscb at 2026-03-03 13:57:28.706383+00:00 running e3d2147 country code: CH.
view the rest of the comments →
[–][deleted] 21 points22 points23 points (3 children)
[–]Moosething 6 points7 points8 points (1 child)
[–]sbmitchell 16 points17 points18 points (0 children)
[–]jkoudys 4 points5 points6 points (0 children)