Program for harmonic mean of numbers | Function that returns harmonic mean . ; Declare sum variables and initialize with zero . ; Driver code
function harmonicMean ( arr , n ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) sum = sum + ( 1 / arr [ i ] ) ; return n / sum ; } let arr = [ 13.5 , 14.5 , 14.8 , 15.2 , 16.1 ] ; let n = arr . length ; document . write ( harmonicMean ( arr , n ) ) ;