import { TreeNodeProps , TreeProps } from '../components/Tree' ; export function depthFirstSearch < T > ( nodes , predicate , greedy ? ) ; export function depthFirstSearch < T > ( nodes , predicate , greedy ? ) ; export function depthFirstSearch < T > ( nodes , predicate , greedy ? ) ; export function depthFirstSearch < T > ( nodes , predicate , greedy = true ) { let list = [ ] ; for ( const node of nodes ) { if ( predicate ( node ) ) { if ( greedy ) { return node ; } list . push ( node ) ; } if ( node . children && node . children . length > 0 ) { if ( greedy ) { return depthFirstSearch ( node . children , predicate , greedy ) ; } const nestedDfs = depthFirstSearch ( node . children , predicate , greedy ) ; if ( nestedDfs ) { list = list . concat ( nestedDfs ) ; } } } return greedy ? null : list ; }