Skip to content

Commit

Permalink
Add utility methods
Browse files Browse the repository at this point in the history
  • Loading branch information
carlssonemil committed Nov 8, 2023
1 parent 8caa8a5 commit 34a5c77
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/utils/array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const groupBy = (array, keyGetter) => {
return array.reduce((map, item) => {
const key = keyGetter(item)
map[key] = map[key] || []
map[key].push(item)
return map
}, {})
}

export { groupBy }
6 changes: 6 additions & 0 deletions src/utils/number.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const round = (number, precision) => {
const factor = Math.pow(10, precision)
return Math.round(number * factor) / factor
}

export { round }

0 comments on commit 34a5c77

Please sign in to comment.