Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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
Comment

PREVIOUS NEXT
Code Example
Javascript :: synaptic js 
Javascript :: double and operator javascript 
Javascript :: three js div over orbitcontrol 
Javascript :: connecting , creating ,reading from mongo 
Javascript :: exemple de modal reactjs 
Javascript :: Shorthand for calling functions conditionally 
Javascript :: lity popup 
Javascript :: component not registered correctly 
Javascript :: react router dom two page form 
Javascript :: faker link for json post req 
Javascript :: vue apollo refetch every x ms 
Javascript :: number and type operators in javascript 
Javascript :: sequelize findall in array 
Javascript :: RegEdt TimeAdj 
Javascript :: react-chartjs-2 donut chart 
Javascript :: javascript fix errora 
Javascript :: Destructing variable assignment 
Javascript :: handle fetch error 
Javascript :: divide string in lines react native max width 
Javascript :: typeerror: chogigabsi eobnun bin beyole dehan recudenun error. 
Javascript :: After installing a basic setup using above command, install below npm packages 
Javascript :: javascript array game 
Javascript :: libfluidsynth npm 
Javascript :: javascript set css after property 
Javascript :: javascript format hour 
Javascript :: jquery 1.6 jgrid pagging ejemplo 
Javascript :: rest in object destructuring 
Javascript :: fb like image window js 
Javascript :: How to select a search bar without a `name`? javascript 
Javascript :: Count recurring digits in number 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =