var a=[0,1,2,3,4,5,6,7,8]
function Search(arr,target){
var left;
var right;
var NotFound=-1;
left=1; //初始化左边界
right=arr.length; //初始化右边界
while(left<=right){
var mid=(left+right)/2; //计算中间元素坐标
if(target<arr[mid]){
right=mid-1; //当目标值小于中间值时,调整右边界
}
else if(target>arr[mid]){
left=mid+1; //当目标值大于中间值时,调整左边界
}
else{
console.log(mid) ; //找到 返回坐标
}
}
return NotFound; //没有找到
}
Search(a,7)