Aggregate functions

🚧

The aggregate function always follows after a .groupBy() function.
At this current version only one aggregation can be performed after a group by.
Note, aggregate functions on a simple array don’t follow a .groupBy().

📘

As an alternative until a future release allows multiple aggregations at once, i.e: …groupBy(‘Location’).sum(‘Age’).min(‘Age’). You can perform two separate jinqJs queries on the same collection each using the different aggregate and then perform an inner join jinqJs query to join the two. However, because each aggregate can take multiple parameters you can perform multiple aggregations of the same type on the same aggregation function.

Each of the aggregate functions can take zero to many arguments. Each argument is the name of the field to perform the aggregation on. Zero arguments are allowed only on simple arrays, such as arrays of numbers or strings. See the example below on aggregating on a simple array.

sum(string, string, ...)
count(string, string, ...)
avg(string, string, ...)
min(string, string, ...)
max(string, string, ...)
sum(...fields: string[]): jinqJs;
count(...fields: string[]): jinqJs;
avg(...fields: string[]): jinqJs;
min(...fields: string[]): jinqJs;
max(...fields: string[]): jinqJs;

Simple Array

var result = new jinqJs()
                 .from([1,2,3,4,5])
                    .sum()
                 .select();

/* result: [15] */

Complex Array