function search(nums, target) { let num= Math.round(nums.length/2) // if(nums.lenght % 2 !=0){ // num =Math.round(num)+1 // } if(nums[num]==target) return num // if(nums[num+1]==target) return num+1 if(target < nums[num]){ return search(nums.slice(0,num),target) } if(target > nums[num]){ return search(nums.slice(num+1),target) } } console.log(search([1,2,3,4], 2))