Add function for counting tree node children
authorMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Mon, 26 Nov 2018 13:37:59 +0000 (14:37 +0100)
committerMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Mon, 26 Nov 2018 13:37:59 +0000 (14:37 +0100)
Feature #14258

Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski@contractors.roche.com>

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 :