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 function processes arguments in the wrong order #946

Open
wo opened this issue Mar 28, 2023 · 0 comments
Open

reduce function processes arguments in the wrong order #946

wo opened this issue Mar 28, 2023 · 0 comments

Comments

@wo
Copy link

wo commented Mar 28, 2023

The documentation gives this example use of reduce:

reduce(function(x, acc) { return x + acc; }, 0, [1, 2, 3]); // => 6

From this, I would expect that the first argument is a function that takes the current result as first argument and the accumulator as second (as in JS's array.reduce). But it seems to be the other way around. For example, reduce(function(x, acc) { return x - acc; }, 1, [1, 2]) returns 0, where I would expect -2.

(The current reduce function seems to loop over the supplied array [1,2] from right to left, passing each value as x and the present result as acc.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant