Add function for counting tree node children
[arvados-workbench2.git] / src / models / tree.ts
index 8b71692b1c8bf8211c606573f99a8876a6392aab..bec2f758a478335e6ef437afe6592dde144ce729 100644 (file)
@@ -98,6 +98,9 @@ export const getNodeDescendants = (id: string, limit = Infinity) => <T>(tree: Tr
 export const countNodes = <T>(tree: Tree<T>) =>
     getNodeDescendantsIds('')(tree).length;
 
+export const countChildren = (id: string) => <T>(tree: Tree<T>) =>
+    getNodeChildren('')(tree).length;
+
 export const getNodeDescendantsIds = (id: string, limit = Infinity) => <T>(tree: Tree<T>): string[] => {
     const node = getNode(id)(tree);
     const children = node ? node.children :