Powered By GitBook
REDUCE_INIT
Reduce a list to a single value

Description

Reduces a list to a single value by evaluating a formula for each item in the list, accumulating to a result value which is then passed to the next evaluation.
The iteration is done from the first item to the last item. The iteration starts by using the 1st item in the list as an initial accumulator value. Alternatively you can use REDUCE\_INIT function instead and provide an initial value.
If the list has only one item, that item is returned. If the list is empty, returns null.

Function signature

1
REDUCE_INIT(list: Array, initialaccumulator: , reducerformula: Function) => Number
Copied!
Parameter
Description
List
List of items to reduce
Initial accumulator
Initial value for the accumulator passed to the first evaluation.
Reducer formula
Formula that returns a reduced result using the current item and the previous accumulated result value

Examples

1
products = [
2
{
3
"name": "Swiss army knife",
4
"price": 60
5
},
6
{
7
"name": "Duct tape",
8
"price": 5
9
},
10
{
11
"name": "Glue",
12
"price": 6
13
}
14
]
Copied!
Formula
Return value
REDUCE_INIT(products, 0, accumulator + item.price)
71
REDUCE_INIT<sum, product>(products, 0, sum + product.price)
71
Last modified 10mo ago
Export as PDF
Copy link