From e2799cb092359038374cde25eb691d667b309383 Mon Sep 17 00:00:00 2001 From: sanine Date: Wed, 25 May 2022 22:22:41 -0500 Subject: add Util.js --- modules/Util.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 modules/Util.js (limited to 'modules/Util.js') diff --git a/modules/Util.js b/modules/Util.js new file mode 100644 index 0000000..cbe466d --- /dev/null +++ b/modules/Util.js @@ -0,0 +1,13 @@ +function useAverage() { + var avg = 0; + let weight = 0; + const append = value => { + avg = (weight * avg) + value; + weight += 1; + avg = avg/weight; + } + + return [() => avg, append]; +} + +export { useAverage }; -- cgit v1.2.1