The type of trees encoded as nested arrays. In this encoding a leaf is
encoded as a single value:
constleaf: TreeArray<number> = 1// A tree with a single node
While a branch node is encoded as a pair of [A, TreeArray<A>[]], with the
first element being the root node value and the second element being its
child nodes encoded as a TreeArray. So if we add two children to our leaf
it would encode as:
constbranch: TreeArray<number> = [1, [2, 3]] // A tree with a 3 nodes
Adding children to a leaf in this encoding converts it into a pair of
[values, nodes]. Here is a larger tree encoded as nested arrays:
The type of trees encoded as nested arrays. In this encoding a leaf is encoded as a single value:
While a branch node is encoded as a pair of
[A, TreeArray<A>[]], with the first element being the root node value and the second element being its child nodes encoded as aTreeArray. So if we add two children to our leaf it would encode as:Adding children to a leaf in this encoding converts it into a pair of
[values, nodes]. Here is a larger tree encoded as nested arrays: