reduce<functionName>(__initial, __iterable);
function functionName(__accumulator, __element) {}
Description
Apply a function to each element of an iterable, reducing it to a single value. Returns the single resulting value (the last accumulator value).
The function argument should be a function accepting two arguments. The first time the accumulator
function argument value will be the initial argument passed to reduce. Every next time the accumulator
argument is the previous result of the function.
When the iterable
argument to reduce is an OBJECT
, the function will be passed an OBJECT
with a single key-value pair in the element argument.
Example
use System; var inputs = [1,2,3]; var sum = reduce<sum>(0, inputs); System.print(sum); // Prints 6 function sum(result, item) { return result + item; }