Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/fathym_common/src/src.deps.ts>sumOf

The Fathym Reference Architecture provides the common foundation for applications built in Typescript.
Go to Latest
function sumOf
import { sumOf } from "https://deno.land/x/fathym_common@v0.0.143/src/src.deps.ts";

Applies the given selector to all elements in the given collection and calculates the sum of the results.

Examples

Example 1

import { sumOf } from "https://deno.land/std@0.224.0/collections/sum_of.ts";
import { assertEquals } from "https://deno.land/std@0.224.0/assert/assert_equals.ts";

const people = [
  { name: "Anna", age: 34 },
  { name: "Kim", age: 42 },
  { name: "John", age: 23 },
];
const totalAge = sumOf(people, (i) => i.age);

assertEquals(totalAge, 99);

Parameters

array: Iterable<T>
selector: (el: T) => number

Returns

number