This is a very useful article, well done! I think I'll use it as the default goto when my friends will ask about it 👀
I like that you showed how map and filter can be used instead of reduce, and then made more of a real-world example 😃
Two things are not quite right tho...
One is that in the header image, and the other image, on the first line there's "using map", but it should be "a filter" I guess.
The other thing is the following comment: // Note: the initialAccValue is optional and defaults to 0 when omitted.
Yes, initialAccValue is optional, but its default is not 0, it's the first element of the array, and the reducer won't even be called with it, so it's risky, even riskier if the array is empty as it will throw a TypeError.
Hi, I'm Monica! I'm a product engineer who is building technology to elevate people and is currently focusing on growing the React Ladies community for React developers.
Hi Raul, Thank you for the feedback. I've updated the comment to correct the mistake re: the default value for initialAccValue and may add more information later re: how it behaves when the initialAccValue is omitted.
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.
This is a very useful article, well done! I think I'll use it as the default goto when my friends will ask about it 👀
I like that you showed how
map
andfilter
can be used instead ofreduce
, and then made more of a real-world example 😃Two things are not quite right tho...
One is that in the header image, and the other image, on the first line there's "using map", but it should be "a filter" I guess.
The other thing is the following comment:
// Note: the initialAccValue is optional and defaults to 0 when omitted
.Yes,
initialAccValue
is optional, but its default is not0
, it's the first element of the array, and the reducer won't even be called with it, so it's risky, even riskier if the array is empty as it will throw aTypeError
.Hi Raul, Thank you for the feedback. I've updated the comment to correct the mistake re: the default value for
initialAccValue
and may add more information later re: how it behaves when theinitialAccValue
is omitted.