npm.io
1.0.0 • Published 10 years ago

@f/reduce

Licence
MIT
Version
1.0.0
Deps
4
Vulns
0
Weekly
0

reduce

Build status Git tag NPM version Code style

Reduce over the elements of a container

Installation

$ npm install @f/reduce

Usage

var reduce = require('@f/reduce')
var fruits = {apples: 2, oranges: 3}
var numFruits = reduce(sum, 0, fruits)

function sum (a, b) {
  return a + b
}

API

reduce(cb, initialValue, collection)
  • cb - Callback called for each collection item with a accumlator value and the current item.
function cb (accumulator, currentItem, key, colllection) {}
  • initialValue - First value for the accumulator
  • arr Collection to be reduced

Returns: The accumulated value

License

MIT