@nodejavascript/array-key-sum

0.1.0 • Public • Published

Install

  npm i @nodejavascript/array-key-sum

Usage

import arrayKeySum from '@nodejavascript/array-key-sum'

const sampleArray = [
  {
    id: 1,
    name: 'Foo',
    cost: 4.50
  },
  {
    id: 2,
    name: 'Bar',
    cost: 4.50
  },
  {
    id: 3,
    name: 'Bar',
    cost: 3.50
  }
]

const sumOfCost = arrayKeySum(sampleArray, 'cost')

// sumOfCost => 12.5

const sumOfCostFoo = arrayKeySum(sampleArray.filter(i => i.name === 'Foo'), 'cost')
const sumOfCostBar = arrayKeySum(sampleArray.filter(i => i.name === 'Bar'), 'cost')

// sumOfCostFoo => 4.5
// sumOfCostBar => 8

Readme

Keywords

Package Sidebar

Install

npm i @nodejavascript/array-key-sum

Weekly Downloads

0

Version

0.1.0

License

ISC

Unpacked Size

2.15 kB

Total Files

4

Last publish

Collaborators

  • nodejavascript