```javascript
var search = function(nums, target) {
let L = 0;
let R = nums.length - 1;
let mid;
while(R >= L){
mid = Math.floor((R+L)/2);
if(target > nums[mid]){
L = mid + 1;
} else if(target < nums[mid]){
R = mid - 1;
} else {
return mid;
}
}
return -1;
};
```