diff options
author | Holden Rohrer <holden.rohrer@gmail.com> | 2019-12-28 15:45:16 -0500 |
---|---|---|
committer | Holden Rohrer <holden.rohrer@gmail.com> | 2019-12-28 15:45:16 -0500 |
commit | 9aba45cb5b786bed64a65e3ec8bcf304a4c97fd1 (patch) | |
tree | a5d735d32c1e2bd2dbd672804302db31b477df7a /utils | |
parent | 53aa7c67f4968e23db32e75b76c30fd3731102a5 (diff) |
integrated array normalizer into vec
Diffstat (limited to 'utils')
-rw-r--r-- | utils/norm.js | 8 | ||||
-rw-r--r-- | utils/vec.js | 4 |
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); +} |