From d8a592aea8cd1d95d694550d93552b3758062244 Mon Sep 17 00:00:00 2001 From: Marcel Gerber Date: Tue, 26 Sep 2023 09:44:25 +0200 Subject: [PATCH] refactor: use map instead of for-loop --- baker/algolia/indexExplorersToAlgolia.ts | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/baker/algolia/indexExplorersToAlgolia.ts b/baker/algolia/indexExplorersToAlgolia.ts index 49add49e324..812d9486086 100644 --- a/baker/algolia/indexExplorersToAlgolia.ts +++ b/baker/algolia/indexExplorersToAlgolia.ts @@ -157,21 +157,15 @@ const getExplorerRecords = async (): Promise => { const textChunksForIteration = textChunks.length ? textChunks : [""] - const explorerRecords = [] - let i = 0 - for (const chunk of textChunksForIteration) { - explorerRecords.push({ - slug, - title: getNullishJSONValueAsPlaintext(title), - subtitle: getNullishJSONValueAsPlaintext(subtitle), - views_7d: - pageviews[`/explorers/${slug}`]?.views_7d || 0, - text: chunk, - objectID: `${slug}-${i}`, - }) - i++ - } - return explorerRecords + + return textChunksForIteration.map((chunk, i) => ({ + slug, + title: getNullishJSONValueAsPlaintext(title), + subtitle: getNullishJSONValueAsPlaintext(subtitle), + views_7d: pageviews[`/explorers/${slug}`]?.views_7d ?? 0, + text: chunk, + objectID: `${slug}-${i}`, + })) }) )