function to find index of element ' x ' in sorted ' arr ' uses binary search technique
function binarySearch ( arr , low , high , x ) { while ( low <= high ) { var mid = parseInt ( ( low + high ) / 2 ) ; if ( arr [ mid ] == x ) return mid ; else if ( arr [ mid ] > x ) high = mid - 1 ; else low = mid + 1 ; } }