Skip to content

sum

Add up numbers related to an array in 1 of 2 ways: 1. Sum all numbers in an array of numbers 2. Sum all numbers returned by a callback function that maps each item in an array to a number.

Usage

sum([1, 2, 3]); // => 6
sum([{ value: 1 }, { value: 2 }, { value: 3 }], (item) => item.value); // => 6
sum([true, false, true], (item) => (item ? 1 : 0)); // => 2

Installation

Terminal window
npx atmx add helper sum