When an event fires, event.composedPath() lists the target first, then its parent, then each ancestor up to the top.
The page is given as parentOf, an object that maps each element's id to its parent's id; the root maps to null. Write eventPath(parentOf, targetId) that returns the ids from targetId up to the root, in that order.
Input: parentOf = {"root":null,"form":"root","field":"form","input":"field","submit":"form","aside":"root"}, targetId = "input" Output: ["input","field","form","root"]
Climb from input through its parents until the root, whose parent is null.
Input: parentOf = {"root":null,"form":"root","field":"form","input":"field","submit":"form","aside":"root"}, targetId = "root" Output: ["root"]
The root has no parent, so the path is just the root.
parentOf has 1 to 10^4 entries and describes a single tree.targetId is a key of parentOf.Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #706 Path of a Click. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.