Reduces an array to an accumulated value by applying a LAMBDA to each element.
Синтаксис
REDUCE(initial_value, array, lambda)Аргументы
initial_valueобязательно
The starting value for the accumulator.
arrayобязательно
The array to be reduced.
lambdaобязательно
A LAMBDA function with two parameters: accumulator and value.
The REDUCE function iterates through an array and applies a custom LAMBDA function to accumulate a single result. It maintains an accumulator that updates with each step, starting from the initial value provided.
=REDUCE(0, {1,2,3}, LAMBDA(a, b, a + b))→6Sums the numbers in the array by starting at 0 and adding each element.
Define the initial value
Set the starting point for your calculation, such as 0 for sums or an empty string for text concatenation.
Create the LAMBDA function
Write a LAMBDA(accumulator, value, ...) that defines how the current value should modify the accumulator.
REDUCE returns only the final accumulated result, whereas SCAN returns an array of all intermediate values.