Function sumBy

  • It will iterate through each element of the provided values array and add the result of invoking iteratee function/property for each element to produce the desired sum.

    Type Parameters

    • Value

    Parameters

    • values: Value[]

      The array to iterate over.

    • iteratee: IterateeT<Value>

      The function/property to get the value per element.

    Returns number

    The sum value.

    Since

    1.0.0

    Example

    sumByFn([1, 2, 3], number => number); // => 6
    

    Example

    sumByFn([{ a: 1 }, { a: 2 }, { a: 3 }], ({ a }) => a); // => 6
    

    Example

    sumBy([{ a: 1 }, { a: 2 }, { a: 3 }], "a"); // => 6