给一个数,去一个已经排好序的数组中寻找这个数的位置(通过快速查找,二分查找)
参考回答:
function binarySearch(target,arr,start,end) { var start = start || 0; var end = end || arr.length-1; var mid = parseInt(start+(end-start)/2); if(target==arr[mid]){ return mid; }else if(target>arr[mid]){ return binarySearch(target,arr,mid+1,end); }else{ return binarySearch(target,arr,start,mid-1); } return -1;