RosettaCodeData/Task/Binary-search/MiniScript/binary-search-2.mini

16 lines
357 B
Plaintext

binarySearch = function(A, value)
low = 0
high = A.len - 1
while true
if high < low then return null
mid = floor((low + high) / 2)
if A[mid] > value then
high = mid - 1
else if A[mid] < value then
low = mid + 1
else
return mid
end if
end while
end function