From 52113ef4d1976c353bda1a0e5f187d8ba93468c7 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 24 Feb 2024 12:46:49 -0400 Subject: data: withSortedList: double-refactor stabletoUnstable magic It's still still magic though. --- src/data/composite/data/withSortedList.js | 22 ++++++++-------------- 1 file 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 -- cgit 1.3.0-6-gf8a5