Skip to content

sum

Add up all items of an array

78 bytes

Usage

Given an array of items, and an optional function to map each item to a number, add up all the items.

import * as _ from 'radashi'
const fish = [
{
name: 'Marlin',
weight: 100,
},
{
name: 'Bass',
weight: 10,
},
{
name: 'Trout',
weight: 15,
},
]
_.sum(fish, f => f.weight) // => 125