Returns true if possibleChild is contained within maxDepth children of parent node. By default only looks at immediate children (maxDepth = 0).

// Just check parentNode for childNode
Trees.hasChild(parentNode, childNode);
// See if parentNode or parentNode's parents have childNode
Trees.hasChild(parentNode, childNode, 1);
// Use custom equality function, in this case comparing on name field
Trees.hasChild(parentNode, childNode, 0, (a, b) => a.name === b.name);
  • Type Parameters

    Parameters

    • parent: T

      Parent tree

    • possibleChild: T

      Sought child

    • eq: IsEqual<T> = isEqualDefault

      Equality function, or isEqualDefault if undefined.

    • maxDepth: number = 0

      Maximum depth. 0 for immediate children, Number.MAX_SAFE_INTEGER for boundless

    Returns boolean