Created
April 22, 2020 14:48
-
-
Save syropian/9a3ca105d7782f7dacff245b9e51a951 to your computer and use it in GitHub Desktop.
Revisions
-
syropian created this gist
Apr 22, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ 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); }