I need to group objects based on overlapping periods.
const periods = [
{start: 1, end: 4},
{start: 1, end: 7},
{start: 1, end: 4},
{start: 5, end: 8},
{start: 9, end: 12},
{start: 9, end: 12}
]
const desiredOutput = [
[{start: 1, end: 4}, {start: 5, end: 8}, {start: 9, end: 12}],
[{start: 1, end: 7}, {start: 9, end: 12}]
[{start: 1, end: 4}]
]
Basically if the periods overlap a new "row" is created, otherwise the object just gets pushed to the row that doesn't.