Created
October 31, 2022 00:13
-
-
Save mogeko/573fb71bdfd2dda62610cc85b8d02a39 to your computer and use it in GitHub Desktop.
This function sums the given numbers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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