I am dealing with a json data in raw format that is unsorted. Here is a snippet of the data:
[
{
"level": 1,
"id": 34,
"name": "example-name",
"father_id": 10
},
...
]
My goal is to organize this data in a specific way as shown below:
...In order to achieve this transformation efficiently, I have implemented the following solution in typescript:
const families: { parent: Treeview; children: Treeview[] }[] = []
arrayTreeViews.forEach(node => {
...
})
I am seeking advice on whether this is the most efficient way to accomplish this task in typescript.
Thank you for any help or suggestions!
EDIT :
[Message deleted because it was the wrong solution]
EDIT 2 : Solution found : so same question as earlier ? Is it the best way / most efficient way to do it ? Thanks for your help / advice
const rootLevel: { parent: Treeview; children: Treeview[] }[] = []
const subLevel: Treeview[] = []
const lowerLevel: Treeview[] = []
arrayTreeViews.forEach(node => {
...
})
subLevel.forEach(node => {
...
res.json(rootLevel)