accumulate-values

v1.0.0
Accumulate values via a reducer
accumulate reduce array string

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

npm i accumulate-values

Metadata

  • MIT
  • >=0.10.0
  • Ben Drucker
  • released 6/6/2015

Downloads

Maintainers