Guest User

Untitled

a guest
Apr 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. function binarySearch(arr, target) {
  2. let min = 0;
  3. let max = arr.length - 1;
  4. while (min <= max) {
  5. const mid = min + Math.floor((max - min) / 2);
  6. if (arr[mid] === target) {
  7. return mid;
  8. }
  9. if (arr[mid] < target) {
  10. min = mid++;
  11. } else {
  12. max = mid--;
  13. }
  14. }
  15. return -1;
  16. }
Add Comment
Please, Sign In to add comment