linq.Average

Averages a set of values

Overloads

  • Number Average ()
  • Number Average (selector)

Number Average ()

Sums the values in the set and divides them by their count

Example

var myArray = [1, 5, 3];
//Returns 3
//(1 + 5 + 3) / 3
myArray.Average();

Number Average (selector)

Sums the values specified by the selector and divides them by the count of elements in the set

Example

var myArray = [{a: 5}, {a: 3}, {a: 1}];
//Returns 2
//(5 - 1 + 3 - 1 + 1 - 1) / 3 = 2
myArray.Average("x => a - 1");

Last edited Sep 23, 2011 at 3:45 AM by mlorbetske, version 2

Comments

No comments yet.