Check whether the given integers a , b , c and d are in proportion | Function that returns true if the given four integers are in proportion ; Array will consist of only four integers ; Sort the array ; Find the product of extremes and means ; If the products are equal ; Driver code
function inProportion ( arr ) { var n = 4 ; arr . sort ( ) ; var extremes = arr [ 0 ] * arr [ 3 ] ; var means = arr [ 1 ] * arr [ 2 ] ; if ( extremes == means ) return true ; return false ; } var arr = [ 1 , 2 , 4 , 2 ] if ( inProportion ( arr ) ) document . write ( " " ) ; else document . write ( " " ) ;