Check if minimum element in array is less than or equals half of every other element | Function to Check if the minimum element in the array is greater than or equal to half of every other element ; Initialise the variables to store smallest and second smallest ; Check if current element is smaller than smallest , the current smallest will become secondSmallest and current element will be the new smallest ; Check if current element is smaller than secondSmallest simply update the latter ; Driver code
function checkMin ( arr , len ) { var smallest = Number . INFINITY , secondSmallest = Number . INFINITY ; for ( var i = 0 ; i < len ; i ++ ) { if ( arr [ i ] < smallest ) { secondSmallest = smallest ; smallest = arr [ i ] ; } else if ( arr [ i ] < secondSmallest ) { secondSmallest = arr [ i ] ; } } if ( 2 * smallest <= secondSmallest ) document . write ( " " ) ; else document . write ( " " ) ; } var arr = [ 2 , 3 , 4 , 5 ] ; var len = 4 ; checkMin ( arr , len ) ;