code: function flattenTree(root) {
    let newChildren = [];
    root.children.forEach(child => {
      const commonParent = getDeepMoreThenOneChild(child);
      if (commonParent.children.length === 0) {
        newChildren.push(commonParent);
      } else {
        newChildren = newChildren.concat(commonParent.children);
      }
    });
    root.children = newChildren;
  }
docs: if root children have only on child we can flatten this