UNPKG

diginext-utils

Version:
18 lines 577 B
/** * Calculates the sum of all elements in an array. * If a key is provided, sums the values of that property from each object. * * @template T - The type of elements in the array * @param array - The array to sum * @param key - Optional key to sum values from objects * @returns The sum of all values, or 0 if array is empty * * @example * ```ts * sum([1, 2, 3, 4]); // 10 * sum([{ value: 5 }, { value: 10 }], 'value'); // 15 * sum([]); // 0 * ``` */ export declare function sum<T = number>(array: T[], key?: keyof T): number; //# sourceMappingURL=sum.d.ts.map