Skip to content

Instantly share code, notes, and snippets.

@mogeko
Created October 31, 2022 00:13
Show Gist options
  • Select an option

  • Save mogeko/573fb71bdfd2dda62610cc85b8d02a39 to your computer and use it in GitHub Desktop.

Select an option

Save mogeko/573fb71bdfd2dda62610cc85b8d02a39 to your computer and use it in GitHub Desktop.

Revisions

  1. mogeko created this gist Oct 31, 2022.
    15 changes: 15 additions & 0 deletions sum.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    /**
    * 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);
    }