Javascript tree search algorithm which return subset of the tree which contains the found term and its parents
问题 I have a tree selection in which every node has a name. I want to search through the node names and return a subset of the tree which only contains the found nodes and its parents. Does anybody know an efficient algorithm in JavaScript for this problem which return the node with all of its parents. Here is an example. when user type a search term, example "Elephant" and the tree looks like this: Elephant Hamster Fish Duck Hamster dog Fish Elephant Fish Dog Fish Unicorn Elephant Elephant