reduce()
Description
Each reducer invocation is passed the current accumulator acc and the first Set value, and returns a new accumulator. The new accumulator is passed to the next reducer invocation with the next Set value.
The accumulator returned by the final reducer invocation is the return value.
Because this method scans the full set, the query can time out for large sets.
Examples
-
For these examples, the product prices are:
{ data: [ { price: 6.98 }, { price: 24.99 }, { price: 4.99 }, { price: 3.99 }, { price: 0.35 }, { price: 3.49 }, { price: 2.99 }, { price: 1.49 }, { price: 23.99 } ] }
-
Count the prices in the Set:
9
-
Find the maximum price in the Set:
24.99
-
Calculate the average price:
{ count: 9, total: 73.26, average: 8.14 }
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!