Array.prototype.findSort=function(num1) {
var hasSortArr=this;
var l=0,r=hasSortArr.length;
var lock=-1;
var dis=0;
var dis1=0,dis2=0;
if(hasSortArr.length>0){
dis1=num1-hasSortArr[0];
if(dis1<=0){
return [0,dis1]
}
dis2=num1-hasSortArr[r-1];
if(dis2>=0){
return [r-1,dis2]
}
while(lock===-1){
var m=(l+r+1)>>1;
//比较下坐标大小
dis=num1-hasSortArr[m]
if(dis>0){
if(m+1===r){
if(dis>-dis2){
lock=r;
dis=dis2;
}else{
lock=m;
}
}else{
dis1=dis;
l=m
}
}else if(dis<0){
if(l+1===m){
if(-dis>=dis1){
lock=l;
dis=dis1;
}else{
lock=m;
}
}else{
dis2=dis;
r=m
}
}else{
lock=m;
}
}
return [lock,dis]
}
return [lock,dis]
}