function reduceGroups
reduceGroups<T, A>(record: Readonly<Record<string, ReadonlyArray<T>>>,reducer: (accumulator: A,current: T) => A,initialValue: A): Record<string, A>Applies the given reducer to each group in the given grouping, returning the results together with the respective group keys.
Examples
Example 1
Example 1
import { reduceGroups } from "@std/collections/reduce_groups"; import { assertEquals } from "@std/assert/assert_equals"; const votes = { "Woody": [2, 3, 1, 4], "Buzz": [5, 9], }; const totalVotes = reduceGroups(votes, (sum, it) => sum + it, 0); assertEquals(totalVotes, { "Woody": 10, "Buzz": 14, });
Type Parameters
Tinput type of an item in a group in the given grouping.
Atype of the accumulator value, which will match the returned record's values.