$$avg
Returns the average of all values in the array
Usage​
{
"$$avg": [ /* values */ ],
"by": /* Transformer */
"default": /* 0 */
}
"$$avg([default],[by]):{input}"
Returns​
BigDecimal
Arguments​
Argument | Type | Values | Required / Default Value | Description |
---|---|---|---|---|
Primary | array | Yes | Array to average | |
default | BigDecimal | 0 | The default value to use for empty values | |
by | Transformer(##current ) | Input is ##current (current element) | "##current" | A transformer to extract a property to sum by (using ##current to refer to the current item) |
Examples​
Input
Definition
Output
[4, 2, 13.45, null]
"$$avg:$"
4.86
[4, 2, 13.45, null]
"$$avg(1):$"
5.11
[
{ "value": 4 },
{ "value": 2 },
{ "value": 13.45 },
{ "value": null }
]
{
"$$avg": "$",
"by": "##current.value"
}
4.86
[
{ "value": 4 },
{ "value": 2 },
{ "value": 13.45 },
{ "value": null }
]
{
"$$avg": "$",
"by": "##current.value",
"default": 1
}
5.11