From 168fd6d42dafa6832f6f5d4c52f23c6d57cba082 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 26 Jun 2023 10:23:37 -0300 Subject: content: generateArtistInfoPageArtworksChunkedList --- src/util/wiki-data.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/util/wiki-data.js') diff --git a/src/util/wiki-data.js b/src/util/wiki-data.js index 382f162..da8312f 100644 --- a/src/util/wiki-data.js +++ b/src/util/wiki-data.js @@ -343,6 +343,33 @@ export function sortEntryThingPairs(data, sortFunction) { return data; } +/* +// Alternate draft version of sortEntryThingPairs. +// See: https://github.com/hsmusic/hsmusic-wiki/issues/90#issuecomment-1607412168 + +// Maps the provided "preparation" function across a list of arbitrary values, +// building up a list of sortable values; sorts these with the provided sorting +// function; and reorders the sources to match their corresponding prepared +// values. As usual, if multiple source items correspond to the same sorting +// data, this retains the source relative positioning. +export function prepareAndSort(sources, prepareForSort, sortFunction) { + const prepared = []; + const preparedToSource = new Map(); + + for (const original of originals) { + const prep = prepareForSort(source); + prepared.push(prep); + preparedToSource.set(prep, source); + } + + sortFunction(prepared); + + sources.splice(0, ...sources.length, prepared.map(prep => preparedToSource.get(prep))); + + return sources; +} +*/ + // Highly contextual sort functions - these are only for very specific types // of Things, and have appropriately hard-coded behavior. -- cgit 1.3.0-6-gf8a5