Skip to content

reduce function processes arguments in the wrong order #946

Description

@wo

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.)

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions