Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. const MAX_NUMBER=100;
  2. const MY_NUMBER=57;
  3. const counter_max =7;
  4.  
  5. let low=0,high=MAX_NUMBER;
  6. let counter=0;
  7.  
  8. while(low <= high){
  9.  
  10. ++counter;
  11.  
  12. let med=Math.round((high+low)/2);
  13. console.log(`L:${low} .. M:${med} .. H:${high}`);
  14.  
  15. if (MY_NUMBER > med){
  16. low=med+1;
  17. }else
  18. if (MY_NUMBER < med){
  19. high = med-1;
  20. }
  21. else
  22. {
  23. console.log(`Your number is ${med} and required ${counter} iters`);
  24. break;
  25. }
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement