Skip to content

Commit

Permalink
refactor: use map instead of for-loop
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelgerber committed Sep 26, 2023
1 parent 18521e6 commit d8a592a
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions baker/algolia/indexExplorersToAlgolia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,21 +157,15 @@ const getExplorerRecords = async (): Promise<ExplorerRecord[]> => {
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}`,
}))
})
)

Expand Down

0 comments on commit d8a592a

Please sign in to comment.