user
Implement a given algorithm.

Input: Binary Search

Output:
assistant
function binary_search(arr, l, r, x) 
{ 
    if (￼r >= l) { 
        var mid = l + (r - l) / 2; 
  
        // If the element is present 
        // at the middle   
        if (arr[mid] == x)  
            return mid; 
  
        // If element is smaller 
        // than mid, then 
        // it can only be present 
        // in left sub array 
        if (arr[mid] > x)  
            return binary_search(arr, l, mid - 1, x); 
  
        // Else the element can 
        // only be present 
        // in right sub array 
        return binary_search(arr, mid + 1, r, x); 
    } 
  
    // We reach here when  
    // element is not present 
    // in array 
    return -1; 
}