aggregate(seed, func[, arg])

suckgamoni edited this page May 14, 2013 · 2 revisions

Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value.

Syntax

Parameters

seed

The initial accumulator value.

func

Type: function(accumulated, value, key, arg)
An accumulator function to be invoked on each element.

arg

An external argument.

Return Value

The final accumulator value.


Example

var ints = [ 4, 8, 8, 3, 9, 0, 7, 8, 2 ];

// Count the even numbers in the array, using a seed value of 0.
var numEven = from(ints).aggregate(0, 
    "(total, next) => next % 2 == 0 ? total + 1 : total");

console.log("The number of even integers is: " + numEven);

// This code produces the following output:
//
// The number of even integers is: 6