Minimum in an array which is first decreasing then increasing | Function to find the smallest number 's index ; Do a binary search ; Find the mid element ; Check for break point ; Return the index ; Print the smallest number
function minimal ( a , n ) { let lo = 0 , hi = n - 1 ; while ( lo < hi ) { let mid = ( lo + hi ) >> 1 ; if ( a [ mid ] < a [ mid + 1 ] ) { hi = mid ; } else { lo = mid + 1 ; } } return lo ; } let a = [ 8 , 5 , 4 , 3 , 4 , 10 ] ; let n = a . length ; let ind = minimal ( a , n ) ; document . write ( a [ ind ] ) ;