getStatsgetStats 方法遍历整个树,并返回一个包含其统计信息的对象。
import { Tree } from '@movk/core'
const tree = [
{ id: 1, children: [
{ id: 2 },
{ id: 3, children: [{ id: 4 }] }
] }
]
const stats = Tree.getStats(tree)
/*
stats 将会是:
{
total: 4, // 总节点数
leafCount: 2, // 叶子节点数
maxDepth: 2, // 最大深度
minDepth: 1 // 最小深度(叶子节点中)
}
*/
getStats<T extends TreeNode>(tree: T[], config?: TreeConfig): { total: number; leafCount: number; maxDepth: number; minDepth: number }
id, pid, children 键名的配置对象。total, leafCount, maxDepth, minDepth 属性的统计对象。