UNPKG

es-grid-template

Version:

es-grid-template

17 lines (16 loc) 419 B
import isLeafNode from "./isLeafNode"; /** Get the height/depth of a tree (0-based) */ export default function getTreeDepth(nodes) { let maxDepth = -1; dfs(nodes, 0); return maxDepth; function dfs(columns, depth) { for (const column of columns) { if (isLeafNode(column)) { maxDepth = Math.max(maxDepth, depth); } else { dfs(column.children ?? [], depth + 1); } } } }