1.0.0 • Published 9 years ago

accumulate-values v1.0.0

Weekly downloads
8
License
MIT
Repository
github
Last release
9 years ago

accumulate-values Build Status

Accumulate values via a reducer

Install

$ npm install --save accumulate-values

Usage

var accumulate = require('accumulate-values')
;[0, 1, 2].reduce(accumulate()) // => 3
;['0', '1', '2'].reduce(accumulate()) // => '012'
;[[0, 1], [2, 3]].reduce(accumulate()) // => 6

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