CollectionReduce

Iterates over every entry of the collection and calls the closure with every element. This function will reduce the array to a single value and will return the value.

Returns: any

Usage

CollectionReduce( collection, closure [, initalValue ] )

Arguments

Argument Description
collection
(object, required)

collection to iterate

closure
(function, required)

function/closure that implements the following constructor [function(... depending on the given collection ...):any].

initalValue
(object, optional)

inital value passed as part of the first closure call

Examples

thresholds = [1, 3, 4, 5];

score = CollectionReduce(thresholds, function(a, b) {
  return a + b^2;
}, 0);

dump(score); // 51

score = thresholds.reduce(function(a, b) {
  return a + b^2;
}, 0);

dump(score); // 51

See also