I'm trying to manipulate an array but I can't seem to get it into the form I want.
Here's the array:
const children = [
{ type: 'span' },
{ type: 'br' },
{ type: 'span' },
{ type: 'br' },
{ type: 'br' },
{ type: 'span' },
{ type: 'br' },
{ type: 'br' },
{ type: 'br' },
{ type: 'span' },
{ type: 'br' },
{ type: 'span' },
]
So the challenge is to create an array of arrays. Whenever there are 2 or more consecutive br values then this signifies where one array ends and the next begins. So I'm trying to get to this:
[
[{type: 'span'}, {type: 'br'}, {type: 'span'}],
[{type: 'span'}],
[{type: 'span'}, {type: 'br'}, {type: 'span'}]
]
Note There could be any amount of consecutive br tags.
Wondering whether reduce would be a better approach than forEach though?