npm.io
1.0.0 • Published 10 years ago

@f/reduce-obj

Licence
MIT
Version
1.0.0
Deps
0
Vulns
0
Weekly
0

reduce-obj

Build status Git tag NPM version Code style

Reduce over an object's key-value pairs

Installation

$ npm install @f/reduce-obj

Usage

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

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

API

reduce(cb, initialValue, obj)
  • cb - Callback called for each key/value pair in obj with an accumlator value and the current item.
function cb (acc, val, key, obj) {}
  • initialValue - First value for the accumulator
  • obj Object to be reduced

Returns: The accumulated value

License

MIT