Skip to content
Yasser Moradi edited this page Sep 1, 2015 · 1 revision

Description:

You can create your own calculations using the Aggregate method. This method is similar to the other aggregate methods like Average , Count and ... . However it allows you specify a custom function. The basic overload accepts a function that has 2 parameters and return a value

Samples:

let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 15, 19];

let aggregate = numbers.asEnumerable().aggregate(0, (acc, next) => acc * 10 + next);

console.log('The basic aggregate => ' + aggregate);

Description:

Sometimes it is necessary to execute the function for every item in a collection, rather than skipping the first value. In such cases you can provide a seed value for the accumulator as the first argument of the Aggregate method

Sample:

let value = ['A', 'B', 'C', 'D'];
aggregate = value.asEnumerable().aggregate('Z', (acc, next) => acc + ',' + next);

console.log(aggregate);

Description:

You can add a result selector. The result selector is executed after the entire process is completed.

Sample:

aggregate = value.asEnumerable().aggregate('Z', (acc, next) => acc + ',' + next, s => s.toLowerCase());

console.log(aggregate);
Clone this wiki locally