Skip to content

Instantly share code, notes, and snippets.

@mogeko
Created October 31, 2022 00:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mogeko/573fb71bdfd2dda62610cc85b8d02a39 to your computer and use it in GitHub Desktop.
Save mogeko/573fb71bdfd2dda62610cc85b8d02a39 to your computer and use it in GitHub Desktop.
This function sums the given numbers.
/**
* This function sums the given numbers.
*
* @param xs - The array to be calculated
* @returns The sum of all elements in the number array
*
* @example
* ```typescript
* sum(); // 0
* sum([1, 2, 3]); // 6
* ```
*/
export function sum(...xs: number[]) {
return xs.reduce((a, b) => a + b, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment