Answers for "javascript average of float array"

0

javascript average of float array

Array.prototype.avg=function(fn){
    fn =fn || function(e,i){return e};
    return (this.map(fn).reduce(function(a,b){return parseFloat(a)+parseFloat(b)},0) / this.length ) ; 
};

[ 1 , 2 , 3].avg() ;  //-> OUT : 2

[{age:25},{age:26},{age:27}].avg(function(e){return e.age}); // OUT : 26
Posted by: Guest on June-16-2021

Code answers related to "javascript average of float array"

Code answers related to "Javascript"

Browse Popular Code Answers by Language