AggregateByField
cartographer / aggregateByField
Function: aggregateByField()
Section titled “Function: aggregateByField()”aggregateByField(
items,groupField,aggregateField,operation):Record<string,number>
Defined in: queries/queryFunctions.ts:29
Apply a numeric aggregation operation to items grouped by a field.
Groups items by groupField, then applies sum/avg/min/max/count to aggregateField values within each group.
Parameters
Section titled “Parameters”Array of items to aggregate
groupField
Section titled “groupField”string
Field key to group by
aggregateField
Section titled “aggregateField”string
Field key containing numeric values to aggregate
operation
Section titled “operation”Type of aggregation: ‘sum’, ‘avg’, ‘min’, ‘max’, or ‘count’
"sum" | "avg" | "min" | "max" | "count"
Returns
Section titled “Returns”Record<string, number>
- Object mapping group keys to aggregated numeric results
Example
Section titled “Example”const byAuthor = aggregateByField(items, 'authors', 'word-count', 'sum');// { 'Lovecraft, H. P.': 150000, 'Smith, Clark Ashton': 85000 }