Data structures - trees

Can someone please explain the last bit of code in the exercise here.
I understand it executed when no children have been removed because the matching data/child has not been found. I did consider whether it was used to climb up the tree?? but I am not sure how this is actioned. Thank you :slight_smile:

Class TreeNode {
constructor(data) { = data;
this.children = ;

addChild(child) {
if (child instanceof TreeNode) { ** if the data exists as an instance of TreeNode as node
} else {
this.children.push(new TreeNode(child)); ** if it is just data, and not a node, then with the data, create an instance
const length = children.length; ** original length of array before attempting to remove a child node or data.
this.children = this.children.filter(child => { **filter method to manipulate array
if (childToRemove instanceof TreeNode){ ** If the data exists as a node
return childToRemove !== child; ** then dont return this node back to the array
} else {
return !== childToRemove; ** if the data isn’t a node, access and dont return anything to array that matches data.
if(length === children.length){ **if the data or node cannot be found, then the array size will not change. **
** this.children.forEach(child => { ** if data is not found, remove **
** child.removeChild(childToRemove);