Program for Mean Absolute Deviation | Function to find mean of the array elements . ; Calculate sum of all elements . ; Function to find mean absolute deviation of given elements . ; Calculate the sum of absolute deviation about mean . ; Return mean absolute deviation about mean . ; Driver code
function Mean ( arr , n ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) sum = sum + arr [ i ] ; return sum / n ; } function meanAbsDevtion ( arr , n ) { let absSum = 0 ; for ( let i = 0 ; i < n ; i ++ ) absSum = absSum + Math . abs ( arr [ i ] - Mean ( arr , n ) ) ; return absSum / n ; } let arr = [ 10 , 15 , 15 , 17 , 18 , 21 ] ; let n = arr . length ; document . write ( meanAbsDevtion ( arr , n ) ) ;