const array = [
{ name: 'one', value: 1 },
{ name: 'one', value: 2 },
{ name: 'two', value: 3 },
{ name: 'one', value: 4 },
];
const result = [
[
{ name: 'one', value: 1 },
{ name: 'one', value: 2 }
],
[
{ name: 'two', value: 3 },
],
[
{ name: 'one', value: 4 },
]
];
const groupAdjacent = (arr, newGroup) =>
arr.reduce((acc, n, i, a) => (
(!i || newGroup(n, a[~-i])) && acc.push([]),
acc.at(-1).push(n),
acc
), []);
const result = groupAdjacent(arr, (c, p) => c.name !== p.name);