Skip to content

Commit

Permalink
fix: Provide a numerical index as the fifth argument of reduce
Browse files Browse the repository at this point in the history
  • Loading branch information
WaldoJeffers committed Jul 20, 2019
1 parent 2e4b892 commit 906230e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/reduce.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ const curry = require('./curry')
const entries = require('./entries')
const then = require('./then')

const reduce = reducer => (acc, value, key, collection) =>
then(result => reducer(result, value, key, collection), acc)
const reduce = reducer => (acc, value, key, collection, index) =>
then(result => reducer(result, value, key, collection, index), acc)

const reduceAll = (reducer, seed, collection) =>
Array.isArray(collection)
? collection.reduce(reduce(reducer), seed)
: entries(collection).reduce(
(acc, [key, value]) => reduce(reducer)(acc, value, key, collection),
(acc, [key, value], index) => reduce(reducer)(acc, value, key, collection, index),
seed
)

Expand Down

0 comments on commit 906230e

Please sign in to comment.