cic-staff-client/src/app/_helpers/array-sum.ts
Spencer Ofwiti 5228842e61 Merge branch 'master' into spencer/docs
# Conflicts:
#	package-lock.json
#	package.json
#	src/app/_eth/accountIndex.ts
#	src/app/_eth/token-registry.ts
#	src/app/_guards/auth.guard.ts
#	src/app/_guards/role.guard.ts
#	src/app/_helpers/array-sum.ts
#	src/app/_helpers/clipboard-copy.ts
#	src/app/_helpers/custom-error-state-matcher.ts
#	src/app/_helpers/custom.validator.ts
#	src/app/_helpers/export-csv.ts
#	src/app/_helpers/global-error-handler.ts
#	src/app/_helpers/http-getter.ts
#	src/app/_helpers/mock-backend.ts
#	src/app/_helpers/read-csv.ts
#	src/app/_helpers/schema-validation.ts
#	src/app/_services/user.service.spec.ts
2021-05-11 20:41:47 +03:00

20 lines
416 B
TypeScript

/**
* 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);
}
/** @exports */
export { arraySum };