Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const MAX_NUMBER=100;
- const MY_NUMBER=57;
- const counter_max =7;
- let low=0,high=MAX_NUMBER;
- let counter=0;
- while(low <= high){
- ++counter;
- let med=Math.round((high+low)/2);
- console.log(`L:${low} .. M:${med} .. H:${high}`);
- if (MY_NUMBER > med){
- low=med+1;
- }else
- if (MY_NUMBER < med){
- high = med-1;
- }
- else
- {
- console.log(`Your number is ${med} and required ${counter} iters`);
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement