@extremejs/utils - v1.0.0-beta.24
    Preparing search index...

    Function sumByFn

    • Sums the numbers returned by a callback, starting at zero. Visits elements in order, skips sparse array holes, and leaves the array unchanged. Exceptions from the callback propagate to the caller.

      Corresponds to Lodash's sumBy(values, iteratee) callback form, passing only the current element. The callback is required and must return a number. Lodash visits array holes with undefined and skips undefined callback results. Its sum starts at the first defined value, which can preserve negative zero.

      Type Parameters

      • Value

      Parameters

      • values: Value[]

        The array to iterate over.

      • iteratee: (value: Value) => number

        A callback that returns a number for the current element.

      Returns number

      The sum, or zero for an empty array. A returned NaN propagates to the result.

      1.0.0

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