SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function bsr(arr, m) {
  2.   let l = 0;
  3.   let r = arr.length - 1;
  4.  
  5.  
  6.   while (l <= r) {
  7.     const mid = (l + (r - l) / 2) | 0;
  8.     const val = arr[mid];
  9.  
  10.     if (val === m) return mid;
  11.     if (m > val) l = mid + 1;
  12.     if (m < val) r = mid - 1;
  13.   }
  14.  
  15.   return -1;
  16. }
  17.  
  18. a = [1, 2, 3, 4, 5, 6, 7, 8, 10, 12];
  19. b = 3;
  20.  
  21. bsr(a, b);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top