Problem, as an interviewer would state it:
"Implement a custom getElementsByClassName(root, className) from scratch, using a recursive tree traversal instead of the built-in DOM method."
Examples:
customGetElementsByClassName(document.body, "box"); // an array of every descendant with class "box"
Clarifying questions expected:
- Should this match an element with MULTIPLE classes, as long as one of them equals the target?
- Depth-first or breadth-first traversal — does the order matter for a real use case?
- Return a live-updating collection (like the real native method does) or a static snapshot array?
Code / implementation expected: Yes — real, direct proof against the REAL native getElementsByClassName, confirming identical results on a real nested DOM tree.