@bytebury/sauce - v2.2.0
    Preparing search index...

    Function sum

    • Sums the elements in the given list. If you pass a list of numbers, it sums them directly. If you pass a list of objects, provide the key to sum.

      Parameters

      • list: number[]

      Returns number

      sum([1, 2, 3]); // 6
      sum([{ x: 1 }, { x: 2 }], "x"); // 3
    • Sums the elements in the given list. If you pass a list of numbers, it sums them directly. If you pass a list of objects, provide the key to sum.

      Type Parameters

      • T extends Record<PropertyKey, number>

      Parameters

      • list: T[]
      • key: keyof T

      Returns number

      sum([1, 2, 3]); // 6
      sum([{ x: 1 }, { x: 2 }], "x"); // 3