removeNode function

bool removeNode(
  1. FNode root,
  2. FNode target
)

Removes target from the tree with root root. Returns false if not found or if it's the root itself.

Implementation

bool removeNode(FNode root, FNode target) {
  for (final child in childrenOf(root)) {
    if (child.id == target.id) {
      final children = _mutableChildrenOf(root);
      children?.removeWhere((c) => c.id == target.id);
      return true;
    }
    if (removeNode(child, target)) return true;
  }
  return false;
}