I have a sorted array full of objects which I'd like to group by an attribute, but only if they're adjacent in the array.
a is sorted by the start attribute.
a = [{name: "joe", start: "9am", end: "10am"},
{name: "joe", start: "10am", end: "11am"},
{name: "harry", start: "11am", end: "12pm"},
{name: "harry", start: "12pm", end: "1pm"},
{name: "harry", start: "1pm", end: "2pm"},
{name: "joe", start: "2pm", end: "3pm"},
{name: "joe", start: "3pm", end: "4pm"}]
I would like to group adjacent objects by the name attribute so the results looks like:
a = [[{name: "joe", start: "9am", end: "10am"},{name: "joe", start: "10am", end: "11am"}],
[{name: "harry", start: "11am", end: "12pm"},{name: "harry", start: "12pm", end: "1pm"},{name: "harry", start: "1pm", end: "2pm"}],
[{name: "joe", start: "2pm", end: "3pm"},{name: "joe", start: "3pm", end: "4pm"}]]