« get me outta code hell

sugar: make accumulateSum set-aware - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/common-util/sugar.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2025-06-14 09:26:26 -0300
committer(quasar) nebula <qznebula@protonmail.com>2025-06-14 09:26:26 -0300
commitc954b8f66e41785375570f0879f2afa17cbd496e (patch)
tree8c2c9a5f069539731f9af47e3769bbb54867aec1 /src/common-util/sugar.js
parentc31dce37cdf383b4358fd5ab1231705ab54a2c78 (diff)
sugar: make accumulateSum set-aware
Diffstat (limited to 'src/common-util/sugar.js')
-rw-r--r--src/common-util/sugar.js4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/common-util/sugar.js b/src/common-util/sugar.js
index 48442b13..9116698f 100644
--- a/src/common-util/sugar.js
+++ b/src/common-util/sugar.js
@@ -116,6 +116,10 @@ export function findIndexOrEnd(array, fn) {
 // returns null (or values in the array are nullish), they'll just be skipped in
 // the sum.
 export function accumulateSum(array, fn = x => x) {
+  if (!Array.isArray(array)) {
+    return accumulateSum(Array.from(array, fn));
+  }
+
   return array.reduce(
     (accumulator, value, index, array) =>
       accumulator +