$$avg
Returns the average of all values in the array
Usage​
{
"$$avg": /* Array to average */,
"default": 0 /* BigDecimal */,
"by": "##current" /* Transformer(##current) */
}
"$$avg([default],[by]):{input}"
note
Concrete values in the usage example are default values.
Returns​
number
(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 ) | ##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.8625
[
4,
2,
13.45,
null
]
"$$avg(1):$"
5.1125
[
{
"value": 4
},
{
"value": 2
},
{
"value": 13.45
},
{
"value": null
}
]
{
"$$avg": "$",
"by": "##current.value"
}
4.8625
[
{
"value": 4
},
{
"value": 2
},
{
"value": 13.45
},
{
"value": null
}
]
{
"$$avg": "$",
"by": "##current.value",
"default": 1
}
5.1125