There is an input array
blocks:[ { value: 1, parent: null }, { value: 2, parent: 0 }, { value: 3, parent: 1 }, { value: 4, parent: 2 }, { value: 5, parent: 1 } ] We need to convert it into a multi-dimensional array of this type.
{ value: 1, parent: null, children: [ { value: 2, parent: 0, children: [ { value: 3, parent: 1, children: [ { value: 4, parent: 2 } ] }, { value: 5, parent: 1 } ] } ] } Please tell me how to implement it on js?
value: 4should be exactly in this place, and on what basisparent: 2does it change toparent: 1? - Yaantparent, if the parent is uniquely determined by its structure itself? - Yaant