Program to find the minimum ( or maximum ) element of an array | javascript program to find minimum ( or maximum ) element in an array . ; If there is single element , return it . Else return minimum of first element and minimum of remaining array . ; If there is single element , return it . Else return maximum of first element and maximum of remaining array . ; Driver code
function getMin ( arr , i , n ) { return ( n == 1 ) ? arr [ i ] : Math . min ( arr [ i ] , getMin ( arr , i + 1 , n - 1 ) ) ; } function getMax ( arr , i , n ) { return ( n == 1 ) ? arr [ i ] : Math . max ( arr [ i ] , getMax ( arr , i + 1 , n - 1 ) ) ; } var arr = [ 12 , 1234 , 45 , 67 , 1 ] ; var n = arr . length ; document . write ( " " + getMin ( arr , 0 , n ) + " " ) ; document . write ( " " + getMax ( arr , 0 , n ) ) ;