Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Exercise: Tree Walker

109 views
Skip to first unread message

Judith Hemp

unread,
Apr 26, 2022, 6:31:32 AM4/26/22
to Intro to JavaScript
//depth first search
nextNode = function(node) {
 
  //go down, first, following the first Child
  if (node.firstChild != null)
  {
      return node.firstChild;
  }
 
  //if no childs: check for siblings
  while (node != null) {
      if(node.nextSibling)
      {
          return node.nextSibling;
      }
    //if no siblings, climb up
    node = node.parentNode;
  }
 
  return null;
};
Reply all
Reply to author
Forward
0 new messages