Skip to content

Average

Eugene Sadovoi edited this page Jul 15, 2016 · 4 revisions

Computes the average of a sequence of values that are obtained by invoking an optional transform function on each element of the input sequence.

Syntax

Average([selector])

Parameters

selector

A transform function to apply to each element. TElement selector(TSource)

Return Value

The average of the sequence of values

Remarks

If no selector function is specified the implementation assumes sequence of number values.

Example

The following code example demonstrates how to use Average to calculate an average.

var fruits = [ "apple", "banana", "mango", "orange", "passionfruit", "grape" ];

var average = Enumerable.asEnumerable(fruits).Average(s => s.Length);

console.log("The average string length is " + average);

// This code produces the following output:
// The average string length is 6.5. 

Try it out

Clone this wiki locally