Skip to content

sum

The getter is a field path of getByPath or a callback function, for extracting numerical values.

Added in v0.0.1

Usage

ts
import { sum } from 'parsnip-kit'

sum([1, 2, 3, 4]) // 10

sum([{ value: 10 }, { value: 20 }], item => item.value) // 30

sum([{ score: 85 }, { score: 95 }], 'score') // 180

API

Type Parameter

ArgTypeDescription
TType of input array

Arguments

ArgTypeOptionalDefaultDescription
dataT[]falseundefinedInput array
getterstring | ((item: T, index: number, arr: T[]) => number)trueundefinedFor extracting numerical values from array elements

Returns

Type
number