import { aggregateGroups } from "https://deno.land/std@0.202.0/collections/mod.ts";
Applies the given aggregator to each group in the given grouping, returning the results together with the respective group keys
Examples
Example 1
Example 1
import { aggregateGroups } from "https://deno.land/std@0.202.0/collections/aggregate_groups.ts";
import { assertEquals } from "https://deno.land/std@0.202.0/assert/assert_equals.ts";
const foodProperties = {
"Curry": ["spicy", "vegan"],
"Omelette": ["creamy", "vegetarian"],
};
const descriptions = aggregateGroups(
foodProperties,
(current, key, first, acc) => {
if (first) {
return `${key} is ${current}`;
}
return `${acc} and ${current}`;
},
);
assertEquals(descriptions, {
"Curry": "Curry is spicy and vegan",
"Omelette": "Omelette is creamy and vegetarian",
});