I am working with a sorted array containing lists of string arrays:
0:['BS', 'MS','KHB', 'CCBPO']
1:['BS', 'MS','KHB', 'HBPO']
2:['BS', 'MS','KHB', 'PBPO']
3:['BS', 'PO','BC', 'BC']
4:['H', 'I','SS', 'ESS']
5:['H', 'I','SS', 'E']
6:['H', 'D','PCD', 'D']
7:['H', 'D','P', 'HP']
ECT
It can be noted that the first parent is always in the first position, like for example 'BS' and 'H'
, followed by the rest.
Converting this information into a hierarchical structure, the first row would look like this:
{
"name": "BS",
"children": [
{
"name": "MS",
"children": [
{
"name": "KB",
"children": [
{
"name": "KHB",
"children": [
{
"name": "CCBPO",
"isTrue": false
},
"isTrue": false
},
"isTrue": false
},
"isTrue": false
},
"isTrue": false
},
"isTrue": false
}
For subsequent rows, we need to check if the parent is the same and add the child in the correct position. For example, in the second row, the child will be added at the end.
Once this hierarchy is established, I intend to convert it into a structured table format. For the initial 4 rows, this conversion would look something like:
0:['BS', 'MS','KHB', 'CCBPO']
1:['', '','', 'HBPO']
2:['', '','', 'PBPO']
3:['', 'PO','BC', 'BC']
This transformation will allow me to visualize the tree data in a tabular manner.