JavaScript program to repeatedly search an element by doubling it after every successful search
function binary_search ( a , x , lo = 0 , hi = null ) { if ( hi == null ) hi = a . length ; while ( lo < hi ) { mid = Math . floor ( ( lo + hi ) / 2 ) ; midval = a [ mid ] ; if ( midval < x ) lo = mid + 1 ; else if ( midval > x ) hi = mid ; else return mid ; } return - 1 ; } function findElement ( a , n , b ) {