« get me outta code hell

data: withSortedList: double-refactor stabletoUnstable magic - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-02-24 12:46:49 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-02-24 13:35:52 -0400
commit52113ef4d1976c353bda1a0e5f187d8ba93468c7 (patch)
treef612fec3ec1e5a43d943175d357d2f5c2e8412f2 /src/data
parent5447c0ac287aec69ce649f22ad926cd2c8b78e6c (diff)
data: withSortedList: double-refactor stabletoUnstable magic
It's still still magic though.
Diffstat (limited to 'src/data')
-rw-r--r--src/data/composite/data/withSortedList.js22
1 files changed, 8 insertions, 14 deletions
diff --git a/src/data/composite/data/withSortedList.js b/src/data/composite/data/withSortedList.js
index 51309e19..9ee0766b 100644
--- a/src/data/composite/data/withSortedList.js
+++ b/src/data/composite/data/withSortedList.js
@@ -107,20 +107,14 @@ export default templateCompositeFrom({
         };
 
         const stableToUnstable =
-          symbols
-            .map(
-              (current, index) =>
-                (index === 0
-                  ? false
-                  : isEqual(current, symbols[index - 1])))
-            .reduce(
-              (accumulator, equalsPrevious, index) =>
-                (index === 0
-                  ? accumulator
-                  : (equalsPrevious
-                      ? push(accumulator, accumulator.at(-1))
-                      : push(accumulator, accumulator.at(-1) + 1))),
-              [0]);
+          symbols.reduce(
+            (accumulator, current, index) =>
+              (index === 0
+                ? push(accumulator, 0)
+                : (isEqual(current, symbols[index - 1])
+                    ? push(accumulator, accumulator.at(-1))
+                    : push(accumulator, accumulator.at(-1) + 1))),
+            []);
 
         const unstableSortIndices =
           originalIndices