Two front-end interview questions The first question
getNodeByClass(root, class a){ //className
// return all nodes that have class a (string)
}
The second question
getNodeByClassPath(root, classpath a){ //classNameHierarchy
// return all nodes that match classpath a (string), only return the lowest child
// a>b>c, return all nodes that have class c (string) and match this query
// Similar to this, return all nodes that meet the conditions. The data structure refers to native JS, and the node methods and interfaces are also
}
- Solve the answer. Use the backtracking method to traverse all points and propose the node that meets the class for each point.
- The answer modifies the screening judgment conditions and proposes the node that meets the query rules. The trick is to process the classpath//classNameHierarchy, then recursively process the result, and compare the recursive parent at the same time. If it meets the requirements, continue the recursion, otherwise return false