arr-reduce
Fast array reduce that also loops over sparse elements.
Last updated 10 years ago by jonschlinkert .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install arr-reduce 
SYNC missed versions from official npm registry.

arr-reduce NPM version Build Status

Fast array reduce that also loops over sparse elements.

Install with npm

npm i arr-reduce --save

Usage

Callback params

The callback is executed on every element in the supplied array:

  • prev: this is the "accumulator". This value is either the result of the last callback invocation, or the initial value if specified.
  • curr: the current array element being looped over
  • i: the index of the current element
  • arr: the array that is being looped over.

Examples

var reduce = require('arr-reduce');

reduce([1, 2, 3, 4, 5], function (prev, curr) {
  return prev + curr;
});
//=> '15'

Pass an initial value:

reduce(['b', 'c'], function (prev, curr) {
  return prev.concat(curr);
}, ['a']);

//=> ['a', 'b', 'c']

Run tests

Install dev dependencies:

npm i -d && npm

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

Author

Jon Schlinkert

License

Copyright (c) 2015 Jon Schlinkert
Released under the MIT license


This file was generated by verb-cli on March 24, 2015.

Current Tags

  • 1.0.1                                ...           latest (10 years ago)

2 Versions

  • 1.0.1                                ...           10 years ago
  • 1.0.0                                ...           10 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (2)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE