A tree.

Type Parameters

  • T

Hierarchy

  • Tree

Constructors

  • Type Parameters

    • T

    Parameters

    • initial_value: T

      Satellite data of the node.

    • children: (T | Tree<T>)[] = []

      An array of children of the node. children can be an array of nodes or raw values or both. Raw values will be converted to leaves.

    Returns Tree<T>

Properties

#children: Tree<T>[] = []

The children of this tree.

value: T

The value of the root of this tree.

Accessors

Methods

  • Performs a breadth-first filter on the tree generated by the node.

    Returns

    An array of Trees that match the filter function provided in BFS order.

    Todo

    The implementation is probably suboptimal.

    Parameters

    • filter: ((_: Tree<T>) => boolean)

      The filter function to use.

        • (_: Tree<T>): boolean
        • Parameters

          Returns boolean

    Returns Tree<T>[]

  • Performs a breadth-first search for the given value.

    Returns

    An array of tree nodes with the given value, appearing in order they were found in the breadth-first search.

    Parameters

    • value: T

      The value to compare against.

    • strict: boolean = true

      Whether to do strict (===) or loose (==) comparsion. Defaults to true (strict).

    Returns Tree<T>[]

  • Performs a depth-first filter on the tree generated by the node.

    Returns

    An array of Trees that match the filter function provided in DFS order.

    Parameters

    • filter: ((_: Tree<T>) => boolean)

      The filter function to use.

        • (_: Tree<T>): boolean
        • Parameters

          Returns boolean

    Returns Tree<T>[]

  • Performs a depth-first search for the given value.

    Returns

    An array of tree nodes with the given value, appearing in order they were found in the depth-first search.

    Parameters

    • value: T

      The value to compare against.

    • strict: boolean = true

      Whether to do strict (===) or loose (==) comparsion. Defaults to true (strict).

    Returns Tree<T>[]

  • Removes one or more child nodes. Does not recurse.

    Returns

    The new list of children.

    Parameters

    • to_remove: T | Tree<T>

      The value or node to remove.

      • Specify a Tree when wanting to remove a specific node.

      • Specify a value of the generic type to remove any first-level children with the given value.

    • by_value: boolean = false

      Whether to remove children by value or by strict comparison between Tree objects. to_remove must be a Tree if false. When to_remove is a Tree and this is true, removes first-level children based on the value of the given node.

    Returns Tree<T>[]

Generated using TypeDoc