You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
They're using different demo functions, and their return values are consistent with those functions. Returning the sum is just a common example use case for [].reduce.
[].reduce starts at the beginning of the array and works its way to the end. [].reduceRight starts at the end and works its way to the beginning. I think the example for [].reduceRight used in the pen might be mildly confusing for those still learning since it reduces nested arrays. Here's an example of both using the same function; note how the output differs:
Activity
QWp6t commentedon Nov 12, 2018
They're using different demo functions, and their return values are consistent with those functions. Returning the sum is just a common example use case for
[].reduce.[].reducestarts at the beginning of the array and works its way to the end.[].reduceRightstarts at the end and works its way to the beginning. I think the example for[].reduceRightused in the pen might be mildly confusing for those still learning since it reduces nested arrays. Here's an example of both using the same function; note how the output differs:sdras commentedon Nov 13, 2018
Yeah @QWp6t you're right, I should make that a little more clear and easy to understand for beginners, since that's who this resource is for.
rimildeyjsr commentedon Oct 2, 2019
@sdras - hello! Can I work on this issue? 🙂