findDeep (树节点查找)
const findDeep = (arr, callbackFn, childrenKey = 'children') => {
if (!callbackFn) {
return null;
}
return arr?.reduce((pre, cur) => {
if (!!pre) return pre;
if (callbackFn(cur)) return cur;
const children = cur[childrenKey] || [];
if (!!children.length) {
return findDeep(children, callbackFn, childrenKey);
}
return pre;
}, null);
};