In our CMS, content entries can reference other entries (components, blocks, authors, assets, etc.).
Before rendering on the frontend, these references need to be resolved into a fully expanded structure.
This exercise focuses on:
- Problem-solving approach
- Code clarity
- Handling real-world edge cases (like circular references)
Each entry has the following structure:
type Entry = {
id: string;
type: string;
fields: Record<string, any>;
};A reference to another entry is represented as:
{ ref: "entryId" }Write a function:
resolveEntry(rootId: string, entries: Record<string, Entry>): anyThat:
-
Takes a root entry ID
-
Resolves all { ref: "id" } objects recursively
-
Returns a fully expanded entry
-
Detects circular references
If a circular reference is found, return:
{ circular: true }const entries = {
"1": {
id: "1",
type: "page",
fields: {
title: "Home",
hero: { ref: "2" },
footer: { ref: "3" }
}
},
"2": {
id: "2",
type: "hero",
fields: {
heading: "Welcome",
cta: { ref: "4" }
}
},
"3": {
id: "3",
type: "footer",
fields: {
text: "© 2026"
}
},
"4": {
id: "4",
type: "button",
fields: {
label: "Get Started",
link: "/start"
}
}
};Call:
resolveEntry("1", entries)Expected Output (Simplified)
{
id: "1",
type: "page",
fields: {
title: "Home",
hero: {
id: "2",
type: "hero",
fields: {
heading: "Welcome",
cta: {
id: "4",
type: "button",
fields: {
label: "Get Started",
link: "/start"
}
}
}
},
footer: {
id: "3",
type: "footer",
fields: {
text: "© 2026"
}
}
}
}Circular Reference Example
const entries = {
"A": {
id: "A",
type: "page",
fields: {
child: { ref: "B" }
}
},
"B": {
id: "B",
type: "block",
fields: {
parent: { ref: "A" }
}
}
};Expected output:
{ circular: true }Notes
-
You can assume entries contains all referenced IDs
-
Focus on correctness, readability, and approach
-
Pseudocode is acceptable if you get stuck