cic-staff-client/src/app/_helpers/array-sum.ts

19 lines
415 B
TypeScript
Raw Normal View History

/**
* Returns the sum of all values in an array.
*
* @example
* Prints 6 for the array [1, 2, 3]:
* ```typescript
* console.log(arraySum([1, 2, 3]));
* ```
*
* @param arr - An array of numbers.
* @return The sum of all values in the array.
*/
function arraySum(arr: Array<number>): number {
return arr.reduce((accumulator, current) => accumulator + current, 0);
2020-12-05 07:29:59 +01:00
}
/** @exports */
2021-05-10 18:15:25 +02:00
export { arraySum };