Skip to content

Instantly share code, notes, and snippets.

@syropian
Created April 22, 2020 14:48
Show Gist options
  • Save syropian/9a3ca105d7782f7dacff245b9e51a951 to your computer and use it in GitHub Desktop.
Save syropian/9a3ca105d7782f7dacff245b9e51a951 to your computer and use it in GitHub Desktop.
const groupSiblingsByKeyValue = (arr, k, v) => {
return arr
.map((o, i, a) => {
if (o[k] === v) {
let j = i;
const group = [];
while (a[j][k] === v) {
group.push(a[j]);
a[j] = false;
j++;
}
return group.length > 1 ? group : o;
} else {
return o;
}
})
.filter(Boolean);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment