Exercise 2: Testing getBreadcrumb() — Possible Solution ==================================================================== THE FUNCTION UNDER TEST ------------------------------ Per this chapter: async function getBreadcrumb(pageId) { const crumbs = []; let currentId = pageId; while (currentId) { const current = await prisma.page.findUnique({ where: { id: currentId } }); if (!current) break; crumbs.unshift(current); currentId = current.parentId; } return crumbs; } TEST SETUP ------------------------------ Using a real three-level-deep chain, e.g. "Programming" (top-level, id 1, parentId null) -> "Web Development" (id 2, parentId 1) -> "React Fundamentals" (id 3, parentId 2), calling getBreadcrumb(3) should produce the full ancestor chain for the deepest page. TRACING THE WALK ------------------------------ currentId starts at 3. First iteration fetches page 3 ("React Fundamentals"), unshifts it (crumbs = [React Fundamentals]), then currentId becomes 2 (its own parentId). Second iteration fetches page 2 ("Web Development"), unshifts it to the FRONT (crumbs = [Web Development, React Fundamentals]), then currentId becomes 1. Third iteration fetches page 1 ("Programming"), unshifts it (crumbs = [Programming, Web Development, React Fundamentals]), then currentId becomes null (Programming's own parentId), ending the loop. CONFIRMATION ------------------------------ The final crumbs array reads root-to-leaf, in the correct display order: Programming, Web Development, React Fundamentals - exactly the order a breadcrumb nav bar should display them in, left to right. WHY THIS WORKS AS AN ANSWER ------------------------------ It correctly traces why unshift() (adding to the front, not push() which would add to the back) is what produces root-to-leaf order despite the walk itself proceeding leaf-to-root, and confirms the result against a real three-level page chain rather than a trivial one-level example that wouldn't actually exercise the loop.