const numbers = [
{ value: 1 },
{ value: 2 },
{ value: 3 },
{ value: 4 },
] as const;
const negatives = [{ value: 3 }, { value: -2 }, { value: 5 }] as const;
const total = Arr.sumBy(numbers, (item) => item.value);
const totalNegatives = Arr.sumBy(negatives, (item) => item.value);
assert.isTrue(total === 10);
assert.isTrue(totalNegatives === 6);
Calculates the sum of values in an array by applying a mapping function to each element.
const numbers = [
{ value: 1 },
{ value: 2 },
{ value: 3 },
{ value: 4 },
] as const;
const negatives = [{ value: 3 }, { value: -2 }, { value: 5 }] as const;
const total = Arr.sumBy(numbers, (item) => item.value);
const totalNegatives = Arr.sumBy(negatives, (item) => item.value);
assert.isTrue(total === 10);
assert.isTrue(totalNegatives === 6);
Calculates the sum of values in an array by applying a mapping function to each element.
const numbers = [
{ value: 1 },
{ value: 2 },
{ value: 3 },
{ value: 4 },
] as const;
const negatives = [{ value: 3 }, { value: -2 }, { value: 5 }] as const;
const total = Arr.sumBy(numbers, (item) => item.value);
const totalNegatives = Arr.sumBy(negatives, (item) => item.value);
assert.isTrue(total === 10);
assert.isTrue(totalNegatives === 6);
Calculates the sum of values in an array by applying a mapping function to each element.
const numbers = [
{ value: 1 },
{ value: 2 },
{ value: 3 },
{ value: 4 },
] as const;
const negatives = [{ value: 3 }, { value: -2 }, { value: 5 }] as const;
const total = Arr.sumBy(numbers, (item) => item.value);
const totalNegatives = Arr.sumBy(negatives, (item) => item.value);
assert.isTrue(total === 10);
assert.isTrue(totalNegatives === 6);
Calculates the sum of values in an array by applying a mapping function to each element.