accumulate-values
Accumulate values via a reducer
Install
$ npm install --save accumulate-values
Usage
var accumulate = require('accumulate-values')
;[0, 1, 2].reduce(accumulate())
;['0', '1', '2'].reduce(accumulate())
;[[0, 1], [2, 3]].reduce(accumulate())
API
accumulate()
-> function
Returns a function to be passed to Array.prototype.reduce. If the first item in the array is a number, future values are added to the initial value. If it is a string, future values are concatenated. If it is an array, future values are concatenated via [].concat
.
License
MIT © Ben Drucker