у меня есть такая структура
const data = [
{
itemType: 'listOrdered',
content: '1',
position: 0,
},
{
itemType: 'listOrdered',
content: '2',
position: 1,
},
{
itemType: 'listOrdered',
content: '3',
position: 2,
},
{
itemType: 'normalText',
content: 'some text',
position: 3,
},
{
itemType: 'listOrdered',
content: 'next',
position: 4,
},
{
itemType: 'listOrdered',
content: 'next',
position: 5,
}
]
мне нужно чтобы на выходе было
const data = [
{
itemType: 'listOrdered',
content: '1',
position: 0,
nextOrderdItems: [
{
itemType: 'listOrdered',
content: '2',
position: 1,
},
{
itemType: 'listOrdered',
content: '3',
position: 2,
},
]
},
{
itemType: 'normalText',
content: 'some text',
position: 3,
},
{
itemType: 'listOrdered',
content: 'next',
position: 4,
nextOrderdItems: [
{
itemType: 'listOrdered',
content: 'next',
position: 5,
}
]
},
]
то есть нужно собирать айтемы из типом listOrdered в один обьект, если попадается тип например noteItem заканчивается, потом если встречается после noteItem опять listOrdered то по також же схеме далее