The second argument of reduce is consumed as soFar, and in context "so far" represents the maximum y value the pointer has visited so far during the operation.
But that's the opposite order from the standard Array.reduce function, where the first argument is the accumulator and the second is the value currently being visited.
(I do realize that in this particular example (and indeed the others provided) the order of the two arguments doesn't actually matter, but that's beside the point.)
You're right. Seems like and oversight or typo. The arguments for reduce should be the same as any other reducer. (accumulated, value) => newAccumulated
Example 4 has:
The second argument of
reduce
is consumed assoFar
, and in context "so far" represents the maximum y value the pointer has visited so far during the operation.But that's the opposite order from the standard Array.reduce function, where the first argument is the accumulator and the second is the value currently being visited.
(I do realize that in this particular example (and indeed the others provided) the order of the two arguments doesn't actually matter, but that's beside the point.)
Other examples have the same issue.
The reduce method is later characterized:
I don't know exactly what this representation format is, but it suggests to me that the first argument is indeed intended to be the accumulator.