Created
April 22, 2020 14:48
-
-
Save syropian/9a3ca105d7782f7dacff245b9e51a951 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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