sumBy (for BigInts) es-toolkit
Returns the sum of the BigInts that a function derives from each element of an array.
This function is available exclusively from es-toolkit/bigint to avoid potential conflicts with similar functions for other numeric types.
Usage
sumBy(items, getValue)
Use sumBy when the BigInts you want to add up are inside objects. Pass a function that pulls the value out of each element, and it adds up everything that function returns.
An empty array returns 0n, and values can be negative.
Parameters
The array of elements to sum.
A function that returns the BigInt to add for each element.
Returns
Returns the sum of every value returned by getValue. Returns 0n for empty arrays.
Source: es-toolkit
Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.