Problem, as an interviewer would state it:
"Implement a minimal querySelectorAll-style engine from scratch — supporting a tag name, .class, #id, and a descendant combinator (space-separated compound selectors like .box .label)."
Examples:
customQuerySelectorAll(document.body, ".box .label");
// every real element matching .label, nested anywhere inside an element matching .box
Clarifying questions expected:
- Does a compound selector need to support combining a tag, class, AND id together (like
div.box#unique), or just one selector type at a time? - Should results be returned in real DOCUMENT order, matching the native method?
- Is only the descendant combinator (a space) in scope, or also child (
>)/sibling (+/~) combinators?
Code / implementation expected: Yes — real, direct proof against the ACTUAL native querySelectorAll, on the identical real jsdom tree, for a class selector, a descendant-combinator selector, and an id selector.