I got the following array:
let data = [
{"title": {number: 1},
"children": [
{"title": {number: 1.1}},
{"title": {number: 1.2}},
{"title": {number: 1.3}},
{"title": {number: 1.4}},
{"title": {number: 1.5}}
]
},
{"title": {number: 2},
"children": [
{"title":{number: 2.1}},
{"title":{number: 2.2},
"children": [
{"title":{number: 2.2.1}},
{"title":{number: 2.2.2}},
{"title":{number: 2.2.3}},
{"title":{number: 2.2.4}}
]
},
{"title":{number: 2.3}},
{"title":{number: 2.4}}
]
},
{"title": {number: 3},
"children": []
}
];
Every element of this array may change its place, new element may be added, existing element may be removed. The task is to recalculate elements numbers in order to maintain their correct order. For example, if element with number 2.2.2
is removed, the other elements become 2.2.1
, 2.2.2
and 2.2.3
. If some element is removed with its children, numbers for all other elements shoud also be recalculated. Any ideas how to do that would be welcome. Thank you