Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -40712,7 +40712,7 @@ <h1>Array.prototype.push ( ..._items_ )</h1>
<emu-clause id="sec-array.prototype.reduce" type="built-in function">
<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.

<p>_callback_ is called with four arguments: the _previousValue_ (value from the previous call to _callback_), the _currentValue_ (value of the current element), the _currentIndex_, and the object being traversed. The first time that callback is called, the _previousValue_ and _currentValue_ can be one of two values. If an _initialValue_ was supplied in the call to `reduce`, then _previousValue_ will be _initialValue_ and _currentValue_ will be the first value in the array. If no _initialValue_ was supplied, then _previousValue_ will be the first value in the array and _currentValue_ will be the second. It is a *TypeError* if the array contains no elements and _initialValue_ is not provided.</p>
<p>`reduce` does not directly mutate the object on which it is called but the object may be mutated by the calls to _callback_.</p>
<p>The range of elements processed by `reduce` is set before the first call to _callback_. Elements that are appended to the array after the call to `reduce` begins will not be visited by _callback_. If existing elements of the array are changed, their value as passed to _callback_ will be the value at the time `reduce` visits them; elements that are deleted after the call to `reduce` begins and before being visited are not visited.</p>
Expand Down Expand Up @@ -40753,7 +40753,7 @@ <h1>Array.prototype.reduce ( _callback_ [ , _initialValue_ ] )</h1>
<emu-clause id="sec-array.prototype.reduceright" type="built-in function">
<h1>Array.prototype.reduceRight ( _callback_ [ , _initialValue_ ] )</h1>
<emu-note>
<p>_callback_ should be a function that takes four arguments. `reduceRight` calls the callback, as a function, once for each element after the first element present in the array, in descending order.</p>
<p>_callback_ should be a function that takes four arguments. `reduceRight` calls _callback_ once for each element present in the array, in descending order, skipping the first call unless _initialValue_ is provided.</p>
<p>_callback_ is called with four arguments: the _previousValue_ (value from the previous call to _callback_), the _currentValue_ (value of the current element), the _currentIndex_, and the object being traversed. The first time the function is called, the _previousValue_ and _currentValue_ can be one of two values. If an _initialValue_ was supplied in the call to `reduceRight`, then _previousValue_ will be _initialValue_ and _currentValue_ will be the last value in the array. If no _initialValue_ was supplied, then _previousValue_ will be the last value in the array and _currentValue_ will be the second-to-last value. It is a *TypeError* if the array contains no elements and _initialValue_ is not provided.</p>
<p>`reduceRight` does not directly mutate the object on which it is called but the object may be mutated by the calls to _callback_.</p>
<p>The range of elements processed by `reduceRight` is set before the first call to _callback_. Elements that are appended to the array after the call to `reduceRight` begins will not be visited by _callback_. If existing elements of the array are changed by _callback_, their value as passed to _callback_ will be the value at the time `reduceRight` visits them; elements that are deleted after the call to `reduceRight` begins and before being visited are not visited.</p>
Expand Down
Loading