def bsearch(array, target)
min = 0
max = array.length - 1
while max >= min
mid = (min + max).div(2)
if target == array[mid]
return mid
end
if target > array[mid]
min = mid + 1
else
max = mid - 1
end
end
return -1
end
puts bsearch([1,2,3,4,5], 1)
To embed this project on your website, copy the following code and paste it into your website's HTML: