UNPKG

@denq/iron-tree

Version:

Build tree and many method for manipulation

17 lines (15 loc) 489 B
module.exports = function traversalTree(tree, node = null, criteria, callback) { const currentNode = node || tree.rootNode; if (!node) { if (typeof criteria === 'function' && criteria(currentNode)) { callback(currentNode); } else if (criteria === null) { callback(currentNode); } } currentNode.traversal(criteria, callback); const children = currentNode.children; children.forEach((item) => { traversalTree(tree, item, criteria, callback); }); }