Skip to content
This repository

Synopsis

myArray.reduce(elementalFunction)
myArray.reduce(elementalFunction, arg1, arg2, ...)

Arguments

elementalFunction described below

arg1, arg2, ... passed unchanged to elemental function

Elemental Function

this The entire ParallelArray

a, b Arguments to be reduced and returned

arg1, arg2, ... Same as the optional arguments passed to reduce

Returns The result of the reducing a and b, typically used in further applications of the elemental function.

Returns

The final value, if the ParallelArray has only 1 element then that element is returned.

Discussion

Reduce is free to group calls to the elemental function in arbitrary ways and order the calls arbitrarily. If the elemental function is associative then the final result will be the same regardless of the ordering. Addition is an example of an associative function and the sum of a ParallelArray will always be the same regardless of the order that reduces calls addition. Average is an example of non-associative function. Average(Average(2, 3), 9) is 5 2/3 while Average(2, Average(3, 9)) is 4. Reduce is permitted to chose whichever call ordering it finds convenient.

Reduce is only required to return a result consistent with some call ordering and is not required to chose the same call ordering on subsequent calls. Furthermore, reduce does not magically resolve problems related to overflow and the well document fact that some floating point numbers are not represented exactly in JavaScript and the underlying hardware.

Reduce does not require the elemental function be commutative since it does induce reordering of the arguments passed to the elemental functions.

Examples

 // Calculate the sum of the elements
 var source = new ParallelArray([1,2,3,4,5]);
 var sum = source.reduce(function plus(a,b) { return a+b; });
Something went wrong with that request. Please try again.