Message from JavaScript discussions

May 2017

— There is a main while loop which contains that stack pop which sets the current node, then a for in loop inside it which iterates

Message permanent page


The main while loop constitutes traversal while the inner for in loop is the iteration. All the properties are iterated before traversing the next nodes

— So if a node has multiple child nodes like 3, they all get added to the stack in one go, then traversed in opposite order, ie discovered as 123 and traversed as 321

Message permanent page

— I see, the algorithm part of wikipedia article is very clear

— The wikipedia one is not stack safe and its not what I coded, but its close. I used metacomposition instead of recursion

Message permanent page

— Same behavior

— Yeah, I saw

— But still, illustrates the point very clearly

— So I made a mistake typing this haha

— I havent slept for 2 weeks due to taking care of a 8 week old puppy

— Oh god

— So the main algorithm uses iterator protocol, but you can also use the Strategy interface which behaves just like an ioc callback

Message permanent page