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

    Function sumBy

    • Sums numbers selected by a callback or property path, starting at positive zero. Visits elements in order, skips sparse array holes, and leaves the array unchanged.

      Supply an explicit selector. Lodash defaults to its identity callback. Both libraries pass only the current element to the callback. Lodash visits array holes with undefined and starts its sum at the first defined value, which can preserve negative zero. Lodash skips undefined callback results. Here, callbacks should return numbers, since an undefined result produces NaN.

      For shorthand calls, use an ExtremeJS get path. Dotted paths traverse nested properties even when a matching literal key exists. Missing, null, or undefined properties contribute zero. Lodash includes null as a value and skips undefined. If every lookup in a nonempty array yields undefined, Lodash returns undefined.

      Type Parameters

      • Value

      Parameters

      • values: Value[]

        The array to iterate over.

      • iteratee: IterateeT<Value>

        A function returning a number or a key or path to a numeric property.

      Returns number

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

      1.0.0

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