Skip to content

Editorial: clarify that reduce skips first call based on initialValue#3818

Open
michaelficarra wants to merge 1 commit intomainfrom
reduce-note
Open

Editorial: clarify that reduce skips first call based on initialValue#3818
michaelficarra wants to merge 1 commit intomainfrom
reduce-note

Conversation

@michaelficarra
Copy link
Copy Markdown
Member

No description provided.

<h1>Array.prototype.reduce ( _callback_ [ , _initialValue_ ] )</h1>
<emu-note>
<p>_callback_ should be a function that takes four arguments. `reduce` calls the callback, as a function, once for each element after the first element present in the array, in ascending order.</p>
<p>_callback_ should be a function that takes four arguments. `reduce` calls _callback_ once for each element present in the array, in ascending order, skipping the first element unless _initialValue_ is provided.</p>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_callback_ is actually called with the first element, just as the first value rather than the second one. I wonder if the next paragraph might be enough to explain that we "skip" the first value, and here we could just write something like this? Without mentioning where we start from, or that we it is called on all elements.

Suggested change
<p>_callback_ should be a function that takes four arguments. `reduce` calls _callback_ once for each element present in the array, in ascending order, skipping the first element unless _initialValue_ is provided.</p>
<p>_callback_ should be a function that takes four arguments. `reduce` calls _callback_ on the elements present in the array, in ascending order.</p>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't actually true though.

image

This comment was marked as outdated.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how you're getting that from what I posted. The function is not called.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants