Driver method to test above
let arr = [ 2 , 3 , 4 , 10 , 40 ] ; let x = 10 ; let n = arr . length let result = binarySearch ( arr , 0 , n - 1 , x ) ; ( result == - 1 ) ? document . write ( " " ) : document . write ( " " + result ) ;