javascript - Refactoring recursive function -


I have tried many times to use iterate instead of recursive, but I can not wrap my head around it . Maybe it is something to do with recursion happening within a loop, even just the pseudo code would also be greatly appreciated.

  var getElementAndDescendants = function (L) {var docFrag = document.createDocumentFragment (); Var children = el.parentElement.querySelectorAll ("tr [data-patented = '" + el.getAttribute ("data-meridia") + "']"); DocFrag.appendChild (L); Var len = children.length; {DocFrag.appendChild (getElementAndDescendants (children [index]) for (Var index = 0; index & lt; index; ++); } Return docFrag; }; Update: This is a small piece of a larger function that tries to solve a pseudo-tree in the DOM, which is made up of TR children who are similar to children. The table contains. Each of those children can have their own children. The solution ends as a recursive function within which there is a recursive function that you see here. So why am I after micro-customization (if any) I tried to keep this question simple and thus eliminated the external function.   

Something like this should be done, but treat it as pseudocode.

  function getElementAndDescendants (L) {/ * in the first out-list of elements "solve" * / Var stack = []; / * Store solution here. * / Solution = {}; Stack.push (l); While (stack.length! = 0) {var el = stack.pop (); Var docFrag = document.createDocumentFragment (); Var children = el.parentElement.querySelectorAll ("tr [data-patented = '" + el.getAttribute ("data-meridia") + "']"); Var children_len = children.length; If (solution in L! And children_len! = 0) {stack.push (L); / * This way, the next time we go to me, we know that my children were first queued and resolved. * / Solution [L] = null; / * My children are not being solved; Line them up and solve them first. * For / var (i = 0; i  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -