Applies the given selector to all elements in the given collection and calculates the sum of the results.
The type of the array elements.
The array to calculate the sum of.
The selector function to get the value to sum.
The sum of all elements in the collection.
import { sumOf } from "@std/collections/sum-of";import { assertEquals } from "@std/assert";const people = [ { name: "Anna", age: 34 }, { name: "Kim", age: 42 }, { name: "John", age: 23 },];const totalAge = sumOf(people, (person) => person.age);assertEquals(totalAge, 99); Copy
import { sumOf } from "@std/collections/sum-of";import { assertEquals } from "@std/assert";const people = [ { name: "Anna", age: 34 }, { name: "Kim", age: 42 }, { name: "John", age: 23 },];const totalAge = sumOf(people, (person) => person.age);assertEquals(totalAge, 99);
Applies the given selector to all elements in the given collection and calculates the sum of the results.