Javascript: Math Functions

(Last Updated On: )

In this post I will show you how to perform math operations such as min, max, etc.

Min:

//Array
var maxValue = Math.min.apply(Math, myArray);

//Object Array
Math.min.apply(Math,myObjectArray.map(function(v){return v,key;}));

Max:

//Array
var maxValue = Math.max.apply(Math, myArray);

//Object Array
Math.max.apply(Math,myObjectArray.map(function(v){return v,key;}));

Sum:

var sumValue = myArray.reduce(function(a, b) { return a + b; }, 0);

Average:

var avgValue = sumValue / myArray.length;

Standard Deviation:

var stdevValue = Math.sqrt(sumValue);