January 2018
Intermediate to advanced
332 pages
7h 36m
English
The search() method that we implemented earlier works great; however, as a developer, you would now need to loop over the returned sub-tree and construct the remainder of the word out of it to be displayed on the UI. That's kind of a hassle, isn't it? What if we can simplify it so that the tree would return the sub-tree along with the remainder of the words that they form? Actually, it's quite easy to achieve this.
We will need to make a small change to our algorithm and add remainders set at each node; that way, whenever a node is recognized, we can add the remainder to that set and also push new elements into this set while creating new nodes. Let's take a look at how this modifies our code:
add(input) { Read now
Unlock full access