@wemap/maths 4.0.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/Utils.js +18 -0
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "directory": "packages/maths"
13
13
  },
14
14
  "name": "@wemap/maths",
15
- "version": "4.0.0",
15
+ "version": "5.0.0",
16
16
  "bugs": {
17
17
  "url": "https://github.com/wemap/wemap-modules-js/issues"
18
18
  },
@@ -25,5 +25,5 @@
25
25
  "wemap"
26
26
  ],
27
27
  "license": "ISC",
28
- "gitHead": "8b72858590fc2ff33fbea4f090de8cd353a7445f"
28
+ "gitHead": "73607e294f29d3f9a41673bfc25ad9489a1da7f4"
29
29
  }
package/src/Utils.js CHANGED
@@ -61,3 +61,21 @@ export function wrap(n, min, max) {
61
61
  const w = ((n - min) % d + d) % d + min;
62
62
  return (w === min) ? max : w;
63
63
  }
64
+
65
+ /**
66
+ * @param {number[]} arr
67
+ * @returns {number}
68
+ */
69
+ export function average(arr) {
70
+ return arr.reduce((a, b) => a + b) / arr.length;
71
+ }
72
+
73
+ /**
74
+ * @param {number[]} arr
75
+ * @returns {number}
76
+ */
77
+ export function std(arr) {
78
+ const n = arr.length;
79
+ const mean = arr.reduce((a, b) => a + b) / n;
80
+ return Math.sqrt(arr.map(x => Math.pow(x - mean, 2)).reduce((a, b) => a + b) / n);
81
+ }