aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--utils/norm.js8
1 files changed, 8 insertions, 0 deletions
diff --git a/utils/norm.js b/utils/norm.js
new file mode 100644
index 0000000..a1a4fb3
--- /dev/null
+++ b/utils/norm.js
@@ -0,0 +1,8 @@
+// Normalizes an array of numbers such that they sum to one
+
+module.exports = function(arr){ // Modifies arr
+ let sum = arr.reduce( (acc, cur) => arr+cur );
+ for (elem of arr)
+ elem = elem/sum;
+ return arr;
+}