There are already some good comments others have made, but I'll add a small comment of my own. Here are two articles written by @machy44
where he implemented his own versions of map and filter. Maybe thinking about how you'd make your own version of these functions could be helpful:
As @andeemarks
points out, these functions basically abstract away the for loop boilerplate.
I thought I'd also add that these are not the only ways to do this kind of thing. For example, Python has list comprehensions that I think are often more clear. I don't think JavaScript has them though.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
There are already some good comments others have made, but I'll add a small comment of my own. Here are two articles written by @machy44 where he implemented his own versions of
map
andfilter
. Maybe thinking about how you'd make your own version of these functions could be helpful:Let's create our own filter method in JS
machy44
Let's create our map method
machy44
A simple version of reduce would be implemented in a similar vein.
Here is a version of reduce I wrote for my article on asynchronous generators:
A normal synchronous version should be a pretty simple cleanup of the above code:
As @andeemarks points out, these functions basically abstract away the
for
loop boilerplate.I thought I'd also add that these are not the only ways to do this kind of thing. For example, Python has list comprehensions that I think are often more clear. I don't think JavaScript has them though.