Нужно преобразовать массив вроде:
[
{value: 'a', depth: 1, children: []},
{value: 'c', depth: 2, children: []},
{value: 'd', depth: 2, children: []},
{value: 'e', depth: 1, children: []},
{value: 'f', depth: 2, children: []},
{value: 'g', depth: 3, children: []},
{value: 'i', depth: 4, children: []},
// depth can bee any int but the integer row is respected
{value: 'j', depth: n, children: []},
// ...
{value: 'z', depth: 3, children: []},
]
в:
[
{value: 'a', depth: 1, children: [
{value: 'c', depth: 2, children: null},
{value: 'd', depth: 2, children: null},
]},
{value: 'e', depth: 1, children: [
{value: 'f', depth: 2, children: [
{value: 'g', depth: 3, children: [
{value: 'i', depth: 4, children: [
{value: 'j', depth: n, children: [
// ...
]},
]},
]},
{value: '', depth: 3, children: null},
]},
]},
]
Любая помощь очень ценится !
Я понимаюЯ должен использовать рекурсивную функцию, но застрял здесь.