How to transfer data from children to parent in the tree object?

Good day, there's a object in the array
[
{
 "id": 1,
 "parentid": null,
 "count": "0",
 "children": [
{
 "id": 2,
 "parentid": 1,
 "count": "89",
 "children": [
{
 "id": 3,
 "parentid": 2,
 "count": "19",
 "children": [
{
 "id": 5,
 "parentid": 3,
 "count": "205"
},
{
 "id": 4,
 "parentid": 3,
 "count": "8"
}
]
}
]
}
]
}
]

I need to pass a value count of children for each parent above, maybe someone knows the solution?
5e96d05806566003960413.png
April 19th 20 at 12:06
2 answers
April 19th 20 at 12:08
Recursively bypass all the tree in depth and calculate for each element the data on his descendants.
April 19th 20 at 12:10
The source tree should be left without asmenini?

Find more questions by tags AlgorithmsJavaScript