kbrsh / wade

:ocean: Blazing fast 1kb search library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Help Needed: How children's Objects are created?

avinashdvv opened this issue · comments

for(var j = 0; j < str.length; j++) {
      var item = str[j];
      var itemLength = item.length - 1;
      var node = index;

      for(var n = 0; n < itemLength; n++) {
        var char = item[n];
        var newNode = node[char];
        newNode = newNode === undefined ? {} : newNode;
        node[char] = newNode;
        node = newNode; // ---> This part i cann't able to understand
      }

When node is set to newNode, all nodes after that are going to be nested inside of node to make a tree. Check out this section of my blog post for an example of the tree and see if you can work it out.

from the general programming perspective node is should set to be an empty object, then why all nodes after that nested inside of node to make a tree.
When I am debugging it with debugger i am only seeing an empty object in node