# 🎄 Tree algorithm 🎄

```javascript
// Original tree data
```

---
### Step 1: 😍
```javascript
// 1) Get all the strings in the tree
const allStrings = getAllStrings(treeData);
```

---
### Step 2 & 3:😌
```javascript
// 2) Get all depth based on string position
// 3) Add parent metadata only from 2nd node
const allStringsWithDepth = addDepthAndParentToNode(allStrings);
```

---
### Step 4:🤔
```javascript
// 4) Get node overview with title, depth and count
const nodesOverview = generateNodesOverview(allStringsWithDepth);
```

---
### Step 5:🤔🤔🤔
```javascript
// 5) Get number of layers in a tree
const numberOfLayers = getNumberOfLayers(nodesOverview);
// => Returne 3
```
---
### Step 6: 😱😱😱

```javascript
// 6) Add placeholder node to all the strings
const completeStrings = addPlaceholderNodeToString(
allStringsWithDepth,
numberOfLayers
);
```

---
### Step 7: 🙏
```javascript
// 7) Build our new tree backbone with depth and widthCount from nodeOverview
const tree = generateTreeBackbone(
completeStrings,
nodesOverview,
numberOfLayers
);
```

---
### Step 8: 🤭
```javascript
// 8) Based on depth & count, calculate the position for each node
let layers = appendPositionsToNode(tree, HORIZONTAL_SPACING);
const treeHeight = getTreeHeight(layers);
```

---
### Step 9: 🙃🙃🙃
```javascript
// 9) Mirror the node if it's CA
if (isRotated) {
layers = appendPositionsTMirrorNode(layers, treeHeight);
}
```


---
### Bonus 🤩🤩🤩:
How to move 2 trees together?
