Skip to content

Commit

Permalink
refactor(array): optimize groupBy function (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
chouchouji authored Dec 3, 2024
1 parent e626bbc commit 4cdaf41
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/array/groupBy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ export function groupBy<T, K extends PropertyKey>(arr: T[], fn: Fn<T, K>): Recor
return arr.reduce(
(result, item) => {
const key = fn(item)
result[key] = result[key] ?? []
result[key].push(item)
;(result[key] ??= []).push(item)
return result
},
{} as Record<K, T[]>,
Expand Down

0 comments on commit 4cdaf41

Please sign in to comment.