#sum
Returns the total of an array of numbers, optionally after a projection.
#sum(array, @x: projection?)Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
array |
path | array |
The numbers, or elements to project. |
projection (optional) |
lambda |
Selects the number from each element. |
Returns
Section titled “Returns”number
Examples
Section titled “Examples”Sum numbers
Section titled “Sum numbers”{ "numbers": [ 1, 2, 3, 4 ]}{ "result": "#sum($.numbers)"}{ "result": 10}Sum a property
Section titled “Sum a property”{ "items": [ { "price": 2 }, { "price": 3 } ]}{ "result": "#sum($.items, @x: @x.price)"}{ "result": 5}