I am facing a challenge with 2 arrays of objects. Let's call them Array A and Array B.
[ { value: 'Node 1', id: 1, childs: [ { value: 'Node 2', id : 2, childs: [ { value: 'Node 3', id: 3 }, { value: 'Node 4', id: 4 } ] } ] } ]
Array B looks like this:
[ { value: 'Node 1', id: 1, childs: [ { value: 'Node 5', id : 5 } ] } ]
I am struggling to merge these two arrays into a single tree structure with the desired result shown below:
[ { value: 'Node 1', id: 1, childs: [ { value: 'Node 2', id : 2, childs: [ { value: 'Node 3', id: 3 }, { value: 'Node 4', id: 4 } ] }, { value: 'Node 5', id : 5 } ] } ]
The complexity of the arrays can vary with more nested child objects. How can I achieve the desired output?