on master help sign in
lib: add pair to library
commitb0ed3483404897b8f6ab95845662e1bf5211ec88 authorMatilde Park <matilde.park@urbit.org> dateWed 17 Aug 2022, 10:17 (4 years ago) parent01ced92
1 file changed+9
lib/lib.js+9
lib/lib.js+9
@@ -287,3 +287,12 @@ export function getOpenGrantsCount() {
287287 }, 0);
288288 return count;
289289}
290+
291+// Groups arrays into an array of arrays with 2 members
292+export const pair = (arr) =>
293+ arr.reduce(function (rows, key, index) {
294+ return (
295+ (index % 2 == 0 ? rows.push([key]) : rows[rows.length - 1].push(key)) &&
296+ rows
297+ );
298+ }, []);