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

Function interleave

client/src/components/helpers/interleave.ts:7–19  ·  view source on GitHub ↗
(
  items: T[],
  separator: (index: number) => T
)

Source from the content-addressed store, hash-verified

5 * @returns An array with separators inserted between items
6 */
7export function interleave<T>(
8 items: T[],
9 separator: (index: number) => T
10): T[] {
11 const result: T[] = [];
12 items.forEach((item, index) => {
13 result.push(item);
14 if (index < items.length - 1) {
15 result.push(separator(index));
16 }
17 });
18 return result;
19}

Callers 3

ExperienceSettingsFunction · 0.90
ExperienceDisplayFunction · 0.90
PortfolioSettingsFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected