docs: 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
  }