diff options
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 |
commit | c954b8f66e41785375570f0879f2afa17cbd496e (patch) | |
tree | 8c2c9a5f069539731f9af47e3769bbb54867aec1 | |
parent | c31dce37cdf383b4358fd5ab1231705ab54a2c78 (diff) |
sugar: make accumulateSum set-aware
-rw-r--r-- | src/common-util/sugar.js | 4 |
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 + |