Guest User

Untitled

a guest
Jun 24th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. const binary = (list , item) => {
  2. let min = 0;
  3. let max = list.length - 1;
  4. let guess;
  5.  
  6. while (min <= max) {
  7. guess = Math.floor((min + max) / 2);
  8.  
  9. if (list[guess] === item) {
  10. return guess;
  11. } else {
  12. if (list[guess] < item) {
  13. min = guess + 1;
  14. } else {
  15. max = guess - 1;
  16. }
  17. }
  18. }
  19.  
  20. return -1;
  21. };
  22.  
  23. console.log(binary([2, 3, 64, 90, 200], 90))
Add Comment
Please, Sign In to add comment