recursive function to get all ancestor nodes of given element
3280
function getAllAncestors(el) {
  var ancestors = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  var nextAncestor = el.parentNode;

  if (!nextAncestor) {
    return ancestors;
  }

  ancestors.push(nextAncestor);
  return getAllAncestors(nextAncestor, ancestors);
}
676665
def ancestors
        a = Array.new
        self.parent._ancestors(a) unless self.parent.nil?
        return a
    end
1044837
function getRootId(node) {
    var ancestor = node;
    while (ancestor.depth > 1) {
        ancestor = ancestor.parentNode;
    }

    var virtualRoot = node.getAncestors()[0];
    return zrUtil.indexOf(virtualRoot.children, ancestor);
}
361635
def get_previous_node(node):
    
    if node.prev_sibling:
        return node.prev_sibling
    if node.parent:
        return get_previous_node(node.parent)
1116239
def get_ancestors(self, limit: int, header: BlockHeader) -> Tuple[BaseBlock, ...]:
        
        ancestor_count = min(header.block_number, limit)

        # We construct a temporary block object
        vm_class = self.get_vm_class_for_block_number(header.block_number)
        block_class = vm_class.get_block_class()
        block = block_class(header=header, uncles=[])

        ancestor_generator = iterate(compose(
            self.get_block_by_hash,
            operator.attrgetter('parent_hash'),
            operator.attrgetter('header'),
        ), block)
        # we peel off the first element from the iterator which will be the
        # temporary block object we constructed.
        next(ancestor_generator)

        return tuple(take(ancestor_count, ancestor_generator))
495696
private Element getChildElement(Element parent) {
	NodeList list = parent.getChildNodes();
	int len = list.getLength();
	for (int i = 0; i < len; i++) {
	    Node node = list.item(i);
	    if (node instanceof Element) {
		return (Element) node;
	    }
	}
	return null;
    }
1289744
function lastAncestor(node, pred) {
  const ancestors = listAncestor(node);
  return lists.last(ancestors.filter(pred));
}
120791
def iter_ancestors(self):
        
        node = self
        while node.up is not None:
            yield node.up
            node = node.up
614781
def get_ancestors(self):
        
        if self.is_root():
            return get_result_class(self.__class__).objects.none()
        return get_result_class(self.__class__).objects.filter(
            tree_id=self.tree_id,
            lft__lt=self.lft,
            rgt__gt=self.rgt)
928732
function parseHierarchy(nodes) {
  let prev = nodes[0], // the previous node
      heads = [[]],    // the set of inserton heads, at each level
      set = heads[0];  // the current insertion set

  nodes.forEach(node => {
    node.children = node.children || [];

    // indented -->
    if (node.level > prev.level) {
      node.level = prev.level + 1; // ensures consistent nesting.
      set = heads[node.level] = prev.children;
    }
    
    // outdented <--
    if (node.level < prev.level) {
      set = heads[node.level] = heads[node.level] || [];
    }

    set.push(node);
    prev = node;
  });

  return heads[0]; // root node set
}
596783
def _get_ancestors_of(self, obs_nodes_list):
        
        if not obs_nodes_list:
            return set()
        return set(obs_nodes_list) | set(self.parent_node)
90457
def _get_ancestors(self, current=None):
        
        if not current:
            current = []
        current.insert(0, self)
        if self.is_root:
            if current:
                return current
        else:
            return self.parent._get_ancestors(current)
699585
def ancestors(self):
        
        ancestors = []
        p = self.parent
        while p is not None:
            ancestors.append(p)
            p = p.parent
        return ancestors
673802
function lastChildElement (parent, callback) {
  for (let child = parent.lastElementChild; child; child = child.previousElementSibling) {
    if (callback(child)) {
      return child
    }
  }
  return null
}
4697
def construct_selector(self, el, attr=''):
        """"""

        selector = deque()
        ancestor = el
        while ancestor and ancestor.parent:
            if ancestor is not el:
                selector.appendleft(ancestor.name)
            else:
                tag = ancestor.name
                prefix = ancestor.prefix
                classes = self.get_classes(ancestor)
                tag_id = ancestor.attrs.get('id', '').strip()
                sel = ''
                if prefix:
                    sel += prefix + '|'
                sel += tag
                if tag_id:
                    sel += '#' + tag_id
                if classes:
                    sel += '.' + '.'.join(classes)
                if attr:
                    sel += '[%s]' % attr
                selector.appendleft(sel)
            ancestor = ancestor.parent
        return '>'.join(selector)
483678
function getAllChildSpans(node) {
  return (
    Array.isArray(node.children)
      ? node.children
          .map(n => (n.spans || []).concat(getAllChildSpans(n)))
          .reduce((all, arr) => all.concat(arr))
      : []
  );
}
542202
def is_descendant_of(self, node):
        
        return self.pk in [obj.pk for obj in node.get_descendants()]