Get Array Median Deviation - Node.js Algorithm

Node.js examples for Algorithm:Statistics

Description

Get Array Median Deviation

Demo Code

Array.prototype.meddev = function( percent ){
    var len = this.length, med = this.median(), arr = [], i = 0;
    for ( ; i < len; i++ )
        arr.push( Math.abs( this[i] - med ) );
    if ( percent ) 
        return Math.round( ( ( arr.median() ) / med ) * 100 );
    return arr.median();
};

Related Tutorials