I've got objects with an id as a string. Each object can be the child of another object. Relations can be guessed from IDs. For exemple:
[
{ id: '1:2:6', ids: ['1', '2', '6'] },
{ id: '1:4', ids: ['1', '4'] },
{ id: '1', ids: ['1'] },
{ id: '1:2', ids: ['1', '2'] },
]
In this exemple, root object is id: 1, which has 2 childrens id: 1:2 and id: 1:4. Finaly, id: 1:2 has a children id: 1:2:6.
I would like to convert this array to another array where childrens are embeded into parents, so the previous array would result in:
[
{
id: '1',
children: [
{
id: '1:2',
children: [
{ id: '1:2:6', children: [] }
],
},
{
id: '1:4',
children: [],
}
],
}
]
I can use ES6. I tried for hours to find a solution using all sort of loops but I can't figure this out. Any help would be appreciated!
