https://github.com/queicherius/sum-by
Sum the elements of an array with an optional iteratee function
https://github.com/queicherius/sum-by
maintained npm-package
Last synced: 4 months ago
JSON representation
Sum the elements of an array with an optional iteratee function
- Host: GitHub
- URL: https://github.com/queicherius/sum-by
- Owner: queicherius
- License: mit
- Created: 2016-12-13T16:32:52.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-05-11T17:21:50.000Z (about 5 years ago)
- Last Synced: 2024-08-09T16:21:34.326Z (11 months ago)
- Topics: maintained, npm-package
- Language: JavaScript
- Size: 24.4 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sum-by
[](https://travis-ci.org/queicherius/sum-by)
[](https://codecov.io/github/queicherius/sum-by) [](https://greenkeeper.io/)> Sum the elements of an array with an optional iteratee function
## Install
```bash
npm install sum-by
```This module can be used for Node.js as well as browsers using [Browserify](https://github.com/substack/browserify-handbook#how-node_modules-works).
## Usage
```js
const _sum = require('sum-by')_sum([1, 2, 3])
// => 6_sum([1, undefined, 3])
// => 4_sum([{foo: 1}, {foo: 2}, {foo: 3}], (x) => x.foo)
// => 6_sum([{foo: 1}, {bar: 2}, {foo: 3}], (x) => x.bar)
// => 2_sum([{foo: 1}, {bar: 2}, {foo: 3}], (x) => x.herp)
// => 0
```## Tests
```bash
npm test
```## Benchmark
```bash
npm run benchmark
```| | Size (uglify + gzip) | Performance | Performance (with iteratee) |
|-----------------------|----------------------|--------------------|-----------------------------|
| sum-by | 148 bytes | 56,339,337 ops/sec | 31,280,534 ops/sec |
| lodash.sumby | 5,233 bytes | 53,324,787 ops/sec | 16,245,337 ops/sec |## Licence
MIT