Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function binarySearch(arr, n){
- var low = 0, high = arr.length-1, mid = Math.floor((low+high)/2);
- while( low<=high ){
- if( arr[mid]==n )
- return mid;
- else if( arr[mid]>n ){
- high = mid-1;
- mid = Math.floor((low+high)/2);
- }
- else if( arr[mid]<n ){
- low= mid+1;
- mid = Math.floor((low+high)/2);
- }
- }
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment