Function sum

Calculates the sum of all elements in the array based on the provided function.

  • Type Parameters

    • T

    Parameters

    • arr: T[]

      Array of items to be summed.

    • fn: (item: T) => number

      Summing function

    Returns number

    const total = sum([1, 2, 3, 4, 5], (num) => num);

    console.log(total); // 15