Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(reduce): forward index to accumulator #2291

Merged
merged 1 commit into from
Jan 29, 2017

Conversation

kwonoj
Copy link
Member

@kwonoj kwonoj commented Jan 17, 2017

Description:
This PR updates reduce to forward index of an element as same as native reduce operator does.

Related issue (if exists):

@coveralls
Copy link

coveralls commented Jan 17, 2017

Coverage Status

Coverage increased (+0.001%) to 97.699% when pulling 30ea6fd on kwonoj:fix-reduce-index into 31cf2bf on ReactiveX:master.


if (!this.hasSeed) {
this.index++;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does index start at 1 if there is no seed?

Copy link
Member Author

Choose a reason for hiding this comment

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

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce

currentIndex The index of the current element being processed in the array. Starts at index 0, if an initialValue is provided, and at index 1 otherwise.

I tried to follow same behavior to native reduce, where it says start from 0 if seed exists, 1 otherwise.

Copy link
Member Author

Choose a reason for hiding this comment

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

maybe I've read spec incorrectly?

Copy link
Contributor

Choose a reason for hiding this comment

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

@kwonoj Nope, you read it correctly. TIL.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe worth documenting this behaviour in the RxJs documentation?

@benlesh benlesh merged commit 30a4ca4 into ReactiveX:master Jan 29, 2017
@kwonoj kwonoj deleted the fix-reduce-index branch January 29, 2017 06:55
@lock
Copy link

lock bot commented Jun 6, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reduce() overload invoked with index=undefined
5 participants