From b644af9c803f81a6d6397c3f06e8ef02acfd1aea Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Tue, 17 Jun 2014 09:38:35 +0100 Subject: [PATCH] Fix: average() API plug-in was one short in its data count. --- api/average().js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/api/average().js b/api/average().js index 8b23963..41e095b 100644 --- a/api/average().js +++ b/api/average().js @@ -22,12 +22,11 @@ */ 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; + var data = this.flatten(); + var sum = data.reduce( function ( a, b ) { + return (a*1) + (b*1); // cast values in-case they are strings + } ); + + return sum / data.length; } );