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

        • (item): number
        • Parameters

          • item: T

          Returns number

    Returns number

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

    console.log(total); // 15