This question evaluates implementation skills for a simplified selector engine, DOM traversal and manipulation, wildcard attribute pattern matching, and ordered string reconstruction from element attributes.
A webpage hides a URL by splitting it into individual characters stored in DOM elements. The DOM structure is deeply nested, and you are not allowed to use the browser’s built-in querySelector/querySelectorAll.
You must implement a simplified selector engine and use it to locate the hidden characters.
<section data-id="23*">
<article data-class="*45">
<div data-tag="*78*">
<b class="ref" value="h"></b>
<b class="ref" value="t"></b>
<b class="ref" value="t"></b>
<b class="ref" value="p"></b>
<!-- ...more <b> nodes each holding one character... -->
</div>
</article>
</section>
Implement:
function querySelectorAll(root, selector) { /* ... */ }
Where selector is a descendant chain separated by spaces, e.g.
section[data-id="23*"] article[data-class="*45"] div[data-tag="*78*"] b.ref
Each segment may contain:
section
,
div
,
b
)
.ref
)
[data-id="PATTERN"]
Attribute filter patterns may include * wildcards:
*
matches
any string (including empty)
"23*"
matches
"23"
,
"230"
,
"23abc"
"*45"
matches
"45"
,
"abc45"
"*78*"
matches
"78"
,
"a78b"
,
"xx78"
querySelectorAll(root, selector)
to return all matching elements in
document order
.
<b class="ref">
nodes and reconstruct the URL by concatenating each node’s
value
attribute in order.
Return the reconstructed URL as a string.
tagName
,
getAttribute(name)
,
classList
, and
children
(or equivalent).
>
,
+
,
:nth-child
, or other CSS features—only the subset described above.