Skip to main content
11 events
when toggle format what by license comment
Sep 17, 2017 at 10:51 comment added mike rodent PPS also there is a slicker way to do the reversing and adding of the child nodes in ES6: stack.push( ... Array.from( node.childNodes ).reverse() ); - no reassignment of stack, so stack can be const.
Sep 16, 2017 at 16:35 comment added mike rodent Very nice... please see my slight variation on this theme, in which you can get the depth of each node as you iterate...
Jul 25, 2015 at 1:09 comment added Andrew @o11c I don't know about a better way, but some may find this easier to read: for (var i = node.childNodes.length-1; i >= 0; i--) { stack.push(node.childNodes[i]); }
Jul 25, 2015 at 1:01 history edited Andrew CC BY-SA 3.0
Changed the word 'simple' to 'concise' to be more clear.
Jul 25, 2015 at 1:00 comment added Andrew @Hosch250 which original version are you referring to? The one with recursion? The original poster was asking for a concise solution without recursion: that's what I was going for.
Jul 24, 2015 at 1:42 comment added o11c I do wonder if it's possible to do the append-all-reversed in a better way. I'm not nearly familiar enough with javascript to know.
Jul 24, 2015 at 1:35 comment added o11c Ooh, clever. I hadn't thought of this as a DFS problem. You deserve more upvotes!
Jul 24, 2015 at 0:31 review Late answers
Jul 24, 2015 at 0:42
Jul 24, 2015 at 0:26 comment added user34073 Can you explain why your alternative version is better than the original version?
Jul 24, 2015 at 0:22 review First posts
Jul 24, 2015 at 0:26
Jul 24, 2015 at 0:13 history answered Andrew CC BY-SA 3.0