Get average from array - Node.js Algorithm

Node.js examples for Algorithm:Statistics

Description

Get average from array

Demo Code

function getAvg(array){
  var sum=0;//from   w w  w  .j av a2  s .c  om
  for (var i=0;i<array.length;i++){
    sum += array[i][1]; 
  }
  var avg = sum / array.length;
  return parseFloat(avg).toFixed(2);
};

Related Tutorials