I need to group array items, if they are the same. But only, if they follow after another.
Single items without same value before or after should be ignored.
Example:
const array = [
{country : 'usa', continent: 'north america'},
{country : 'germany', continent: 'europe'},
{country : 'france', continent: 'europe'},
{country : 'india', continent: 'asia'},
{country : 'netherlands', continent: 'europe'},
]
The result should be:
[
{country : 'usa', continent: 'north america'},
[
{country : 'germany', continent: 'europe'},
{country : 'france', continent: 'europe'}
],
{country : 'india', continent: 'asia'},
{country : 'netherlands', continent: 'europe'},
]
]
This solution also would work:
[
{country : 'usa', continent: 'north america'},
{grouped: 'continent', countries: [
{country : 'germany', continent: 'europe'},
{country : 'france', continent: 'europe'}
]
},
{country : 'india', continent: 'asia'},
{country : 'netherlands', continent: 'europe'},
]
]