1Array.prototype.avg=function(fn){
2 fn =fn || function(e,i){return e};
3 return (this.map(fn).reduce(function(a,b){return parseFloat(a)+parseFloat(b)},0) / this.length ) ;
4};
5
6[ 1 , 2 , 3].avg() ; //-> OUT : 2
7
8[{age:25},{age:26},{age:27}].avg(function(e){return e.age}); // OUT : 26