How can i convert an array of objects into nested objects based on the values between start and end?
Assume that i have an array like this:
const array = [
{
"content": "_88888888888 ~*8888888888*~ *8888888*_",
"start": 5,
"end": 37
},
{
"content": "~*88888*~",
"start": 18,
"end": 27
},
{
"content": "*88888*",
"start": 19,
"end": 26
},
{
"content": "*88888*",
"start": 29,
"end": 36
}
]
I want to convert it that:
const array = [
{
"content": "_88888888888 ~*88888*~ *88888*_",
"start": 5,
"end": 37,
"children": [
{
"content": "~*88888*~",
"start": 18,
"end": 27,
"children": [
{
"content": "*8888888888*",
"start": 19,
"end": 26
},
]
},
{
"content": "*88888*",
"start": 29,
"end": 36
}
]
}
]
As you can see, in expected result, every child values have parent object that matchs start and end value.