Take a starting value. Then, for each element of an array, calculate the next value, using the previous value and the element.
Arguments
| Name | Type | Description | Required |
|---|---|---|---|
array | [any] | Each element of this array gets run through the function f, combined with the previous output from f, and then used for the next run. | Yes |
initial | any | The first time f is run, it will be called with the first item of array and this initial starting value. | Yes |
f | fn(any, accum: any): any | Run once per item in the input array. This function takes an item from the array, and the previous output from f (or initial on the very first run). The final time f is run, its output is returned as the final output from reduce. | Yes |
Returns
any - The any type is the type of all possible values in KCL. I.e., if a function accepts an argument with type any, then it can accept any value.