MCPcopy Create free account
hub / github.com/freeCodeCamp/freeCodeCamp / filterByBlock

Function filterByBlock

curriculum/src/filter.ts:10–24  ·  view source on GitHub ↗
(
  superblocks: T[],
  { block }: { block?: string } = {}
)

Source from the content-addressed store, hash-verified

8 * @returns {Array<Object>} Array with one superblock containing the specified block, or the original array if block is not provided.
9 */
10export function filterByBlock<T extends { blocks: { dashedName: string }[] }>(
11 superblocks: T[],
12 { block }: { block?: string } = {}
13): T[] {
14 if (!block) return superblocks;
15
16 const remainingSuperblocks = superblocks
17 .map(superblock => ({
18 ...superblock,
19 blocks: superblock.blocks.filter(({ dashedName }) => dashedName === block)
20 }))
21 .filter(superblock => superblock.blocks.length > 0);
22
23 return remainingSuperblocks;
24}
25
26/**
27 * Filters the superblocks array to only include superblocks with the specified name(s).

Callers 1

filter.test.jsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected