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

"reduce" callback gets incorrect index #172

Closed
vitaly-t opened this issue Oct 27, 2022 · 1 comment
Closed

"reduce" callback gets incorrect index #172

vitaly-t opened this issue Oct 27, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@vitaly-t
Copy link
Owner

vitaly-t commented Oct 27, 2022

import {pipe, reduce} from 'iter-ops';

const input = [3, 0, -2, 5, 9, 4];

const i = pipe(input, reduce((prev, curr, idx, state) => {
    console.log(idx);
    return prev;
}));

const r = [...i];

Expected Output:
1 2 3 4 5

Actual Output
2 4 6 8 10

As a test against the standard reduce...

  • without initial value:
input.reduce((prev, curr, idx)=>{
    console.log(idx);
    return prev;
});

Outputs: 1 2 3 4 5

  • with initial value:
input.reduce((prev, curr, idx)=>{
    console.log(idx);
    return prev;
}, 0);

Outputs: 0 1 2 3 4 5

@vitaly-t vitaly-t added the bug Something isn't working label Oct 27, 2022
vitaly-t added a commit that referenced this issue Oct 27, 2022
vitaly-t added a commit that referenced this issue Oct 27, 2022
@vitaly-t
Copy link
Owner Author

This issue was fixed and released in v2.1.1

@vitaly-t vitaly-t changed the title Incorrect index passed in operator "reduce" "reduce" callback gets incorrect index Oct 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant