1.0.3 • Published 6 years ago

sum-by v1.0.3

Weekly downloads
20
License
MIT
Repository
github
Last release
6 years ago

sum-by

Build Status Coverage Status Greenkeeper badge

Sum the elements of an array with an optional iteratee function

Install

npm install sum-by

This module can be used for Node.js as well as browsers using Browserify.

Usage

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

npm test

Benchmark

npm run benchmark
Size (uglify + gzip)PerformancePerformance (with iteratee)
sum-by148 bytes56,339,337 ops/sec31,280,534 ops/sec
lodash.sumby5,233 bytes53,324,787 ops/sec16,245,337 ops/sec

Licence

MIT