function getVisibleNodeCount({ treeData }) {
  const traverse = node => {
    if (
      !node.children ||
      node.expanded !== true ||
      typeof node.children === 'function'
    ) {
      return 1;
    }

    return (
      1 +
      node.children.reduce(
        (total, currentNode) => total + traverse(currentNode),
        0
      )
    );
  };

  return treeData.reduce(
    (total, currentNode) => total + traverse(currentNode),
    0
  );
}
Count all the visible (expanded) descendants in the tree data.

@param {!Object[]} treeData - Tree data

@return {number} count