Scans an array by applying a LAMBDA to each value and returns an array that has each intermediate value.
구문
SCAN(initial_value, array, lambda)인수
initial_value필수
The starting value for the accumulator.
array필수
The array to be scanned.
lambda필수
A LAMBDA function with two parameters: accumulator and value.
The SCAN function iterates through an array and applies a LAMBDA function to each element, maintaining an accumulator that updates at every step. It returns an array of the same size as the input, showing the progression of the calculation.
=SCAN(0, {1, 2, 3}, LAMBDA(a, v, a+v))→{1, 3, 6}Calculates the running total of the array {1, 2, 3} starting from 0.
Define the initial value
Set the starting point for your calculation (e.g., 0 for sums).
Write the LAMBDA function
Create a LAMBDA that takes two arguments: the accumulator and the current array element.
SCAN returns an array of all intermediate results, whereas REDUCE only returns the final accumulated value.