accumulate-values

1.0.0 • Public • Published

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

Package Sidebar

Install

npm i accumulate-values

Weekly Downloads

4

Version

1.0.0

License

MIT

Last publish

Collaborators

  • bendrucker