diff --git a/smath/CHANGELOG.md b/smath/CHANGELOG.md index 5b18d25d..a7c818d0 100644 --- a/smath/CHANGELOG.md +++ b/smath/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.1.6 + +- Add `avg` function + ## 1.1.5 - Add `linspace` and `logspace` functions diff --git a/smath/package.json b/smath/package.json index 151f6936..a692630c 100644 --- a/smath/package.json +++ b/smath/package.json @@ -1,6 +1,6 @@ { "name": "smath", - "version": "1.1.5", + "version": "1.1.6", "description": "Small math function library", "homepage": "https://npm.nicfv.com/smath", "main": "dist/index.js", @@ -24,6 +24,9 @@ "library", "simple", "number", + "avg", + "average", + "mean", "interpolate", "interpolation", "extrapolate", diff --git a/smath/src/index.ts b/smath/src/index.ts index 917ad23b..f8ff677b 100644 --- a/smath/src/index.ts +++ b/smath/src/index.ts @@ -9,6 +9,18 @@ * useful interpolation and extrapolation functions. */ export abstract class SMath { + /** + * Compute the average, or mean, of a set of numbers. + * @param n Any amount of numeric inputs + * @returns The average, or mean + * @example + * ```js + * const mean = SMath.avg(1, 2, 3, 4); // 2.5 + * ``` + */ + public static avg(...n: Array): number { + return n.reduce((prev, curr) => prev + curr) / n.length; + } /** * Clamp a number within a range. * @param n The number to clamp