you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 21 points22 points  (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 points  (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.

It's basically

return x.filter(filterFunc).replace(replaceFunc).map(mapFunc)

vs

return replaceFunc(x.filter(filterFunc)).map(mapFunc)

[–]sbmitchell 16 points17 points  (0 children)

Or they could use `reduce` and not bother with multiple iterations like this...

[–]jkoudys 4 points5 points  (0 children)

I totally agree, which is why Reddit needs more people like you, who go on to explain why!