Sum and Product of minimum and maximum element of an Array | Function to find minimum element ; Function to find maximum element ; Function to get Sum ; Function to get product ; Driver Code ; Sum of min and max element ; Product of min and max element
function getMin ( arr , n ) { let res = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) res = Math . min ( res , arr [ i ] ) ; return res ; } function getMax ( arr , n ) { let res = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) res = Math . max ( res , arr [ i ] ) ; return res ; } function findSum ( arr , n ) { let min = getMin ( arr , n ) ; let max = getMax ( arr , n ) ; return min + max ; } function findProduct ( arr , n ) { let min = getMin ( arr , n ) ; let max = getMax ( arr , n ) ; return min * max ; } let arr = [ 12 , 1234 , 45 , 67 , 1 ] ; let n = arr . length ; document . write ( " " + findSum ( arr , n ) + " " ) ; document . write ( " " + findProduct ( arr , n ) + " " ) ;