Skip to content

Commit

Permalink
Creates some array helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Rhodes committed May 24, 2018
1 parent 6ae875a commit e3b63a0
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/matchbox/src/helpers/array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const groupBy = (list, groupingKey) => list.reduce((acc, item) => {
const index = item[groupingKey];
return { ...acc, [index]: [ ...(acc[index] || []), item ] };
}

export const groupByValues = (list, groupingKey) => Object.values(groupBy(list, groupingKey))

0 comments on commit e3b63a0

Please sign in to comment.