toArray() {
    const array = [];
    const queue = new Queue();
    const visited = new Map();

    if (this.root) { queue.add(this.root); }

    while (!queue.isEmpty()) {
      const current = queue.remove();
      array.push(current && current.value);

      if (current) { visited.set(current); }

      if (current && !visited.has(current.left)) { queue.add(current.left); }
      if (current && !visited.has(current.right)) { queue.add(current.right); }
    }

    return array;
  }
Represent Binary Tree as an array.

Leaf nodes will have two `undefined` descendants.

The array representation of the binary tree is as follows:

First element (index=0) is the root.
The following two elements (index=1,2) are descendants of the root: left (a) and right (b).
The next two elements (index=3,4) are the descendants of a
The next two elements (index=5,6) are the descendants of b and so on.

 0     1            2             3       4        5       6        n
[root, a=root.left, b=root.right, a.left, a.right, b.left, b.right, ...]

You can also find the parents as follows

e.g.
Parent 0: children 1,2
Parent 1: children 3,4
Parent 2: children 5,6
Parent 3: children 7,8

Given any index you can find the parent index with the following formula:

parent = (index) => Math.floor((index-1)/2)