aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/norm.js8
-rw-r--r--utils/vec.js4
2 files changed, 4 insertions, 8 deletions
diff --git a/utils/norm.js b/utils/norm.js
deleted file mode 100644
index a1a4fb3..0000000
--- a/utils/norm.js
+++ /dev/null
@@ -1,8 +0,0 @@
-// 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;
-}
diff --git a/utils/vec.js b/utils/vec.js
index f4a625c..3996fc2 100644
--- a/utils/vec.js
+++ b/utils/vec.js
@@ -27,3 +27,7 @@ exports.dot = function(orig,vec){
exports.tileToChar = function(orig){
return exports.dot(orig, [8,16]);
}
+exports.norm = function(orig){
+ let sum = orig.reduce( (acc, cur) => acc+cur );
+ return exports.dot(orig, 1/sum);
+}