From 9aba45cb5b786bed64a65e3ec8bcf304a4c97fd1 Mon Sep 17 00:00:00 2001 From: Holden Rohrer Date: Sat, 28 Dec 2019 15:45:16 -0500 Subject: integrated array normalizer into vec --- utils/norm.js | 8 -------- utils/vec.js | 4 ++++ 2 files changed, 4 insertions(+), 8 deletions(-) delete mode 100644 utils/norm.js 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); +} -- cgit