Skip to content

Commit

Permalink
Smath v1.1.6 (#54)
Browse files Browse the repository at this point in the history
avg
  • Loading branch information
nicfv authored Mar 19, 2024
1 parent 66b9a56 commit 6919a31
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions smath/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.1.6

- Add `avg` function

## 1.1.5

- Add `linspace` and `logspace` functions
Expand Down
5 changes: 4 additions & 1 deletion smath/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -24,6 +24,9 @@
"library",
"simple",
"number",
"avg",
"average",
"mean",
"interpolate",
"interpolation",
"extrapolate",
Expand Down
12 changes: 12 additions & 0 deletions smath/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>): number {
return n.reduce((prev, curr) => prev + curr) / n.length;
}
/**
* Clamp a number within a range.
* @param n The number to clamp
Expand Down

0 comments on commit 6919a31

Please sign in to comment.