To me, none of the listed differences is true: the outcome of reduce() doesn't have to be a single value - it can be an object, an array of greater/smaller size, or nearly anything; you can access any array item from within other high order methods (like map() or forEach()) at any step, using it's entire set of arguments; you can drag accumulator value in thisArg of above-mentioned methods just as easy.
Single value doesn't mean it can't be a collection type I think is the OP's point. For example you can use reduce to easily make a lookup map out of an array:
To me, none of the listed differences is true: the outcome of
reduce()
doesn't have to be a single value - it can be an object, an array of greater/smaller size, or nearly anything; you can access any array item from within other high order methods (likemap()
orforEach()
) at any step, using it's entire set of arguments; you can drag accumulator value inthisArg
of above-mentioned methods just as easy.True. Thanks for sharing.
β Still a very good article. πππCongrats to the author.
Thank you for your kind words. :)
Thank you for your feedback. Quoting MDN, the documentation does say it returns a
single value
.I'm pretty new to the method, may I know more about your last reference to
thisArg
please?Single value doesn't mean it can't be a collection type I think is the OP's point. For example you can use reduce to easily make a lookup map out of an array:
Yes, thank you for a nice example.