You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Plugins/api/average().js

21 lines
433 B
JavaScript

/**
* Average the values in a data set.
* @name average()
* @author [Allan Jardine](http://sprymedia.co.uk)
* @requires DataTables 1.10+
*
* @example
* table.column( 3 ).data().average();
*/
jQuery.fn.dataTable.Api.register( 'average()', function () {
var i=0;
var sum = this.flatten().reduce( function ( a, b ) {
i++;
return (a*1) + (b*1); // cast values in-case they are strings
} );
return sum / i;
} );