Get Array Standard Deviation - Node.js Algorithm

Node.js examples for Algorithm:Statistics

Description

Get Array Standard Deviation

Demo Code

Array.prototype.stddev = function( percent ){
    var len = this.length, avg = this.mean(), tot = 0, i = 0;
    for ( ; i < len; i++ )
        tot += Math.pow( this[i] - avg, 2 );       
    if ( percent ) 
        return Math.round( ( ( Math.sqrt( tot / len ) ) / avg ) * 100 );
    return Math.round( Math.sqrt( tot / len ) );
};

Related Tutorials