Problem, as an interviewer would state it:
"Implement a search-text highlighter: given a container element and a query string, wrap every real occurrence of that query (case-insensitive) in a <mark> element, without disturbing any other DOM structure."
Examples:
highlightText(container, "quick"); // both "Quick" and "quick" get wrapped in <mark>
Clarifying questions expected:
- Should this search across MULTIPLE separate text nodes within the container, or only within a single text node?
- Case-sensitive or case-insensitive matching by default?
- What real characters in the query need escaping, given the search is implemented with a regular expression?
Code / implementation expected: Yes — real, direct proof against a real jsdom container confirming correct, case-insensitive matches wrapped in real <mark> elements, with all surrounding text preserved exactly.