Imagine having a collection of objects with parent-child relationships like the one shown below:
[
{ A1: [ "B1" ] },
{ B1: [ "C11", "C12", "C13" ] },
{ C11: [ "D100", "D111", "D112", "D113", "D131" ] },
{ D100: [ "E1000", "E1100" ] }
]
How would you go about transforming the above array into a hierarchical object that accurately represents these relationships? The resulting object should look like this:
{
A1:
{
B1:
{
C11:
{
D100: ["E1000", "E1100"],
D111: [],
D112: [],
D113: [],
D131: []
},
C12: [],
C13: []
}
}
}
I have attempted various recursive methods utilizing reduce, but I am still struggling to successfully convert all levels.