aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHolden Rohrer <holden.rohrer@gmail.com>2019-12-28 15:45:16 -0500
committerHolden Rohrer <holden.rohrer@gmail.com>2019-12-28 15:45:16 -0500
commit9aba45cb5b786bed64a65e3ec8bcf304a4c97fd1 (patch)
treea5d735d32c1e2bd2dbd672804302db31b477df7a
parent53aa7c67f4968e23db32e75b76c30fd3731102a5 (diff)
integrated array normalizer into vec
-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);
+}