Search
IEnumerable.sum Method
See Also
 






Computes the sum of the sequence of number values that are obtained by invoking a transform function on each element.

Namespace: MindFusion.Common.Collections
File: IEnumerable.js

 Syntax

JavaScript  Copy Code

function sum (selector)

 Parameters

selector

function. A transform function to invoke on each element.

 Return Value

Number. The sum of the number values in the sequence.

 Example

The following code implements sum on a list with product instances:

JavaScript  Copy Code

var product1 = new Object();
product1.title = "Ford";
product1.price = 25345;

var product2 = new Object();
product1.title = "BMW";
product1.price = 75300;

productList.addRange([product1, product2]);


productList.items().sum(function (a, b)
{
      return a.price + b.price.valueOf();
});

 See Also