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

8 lines
281 B
Plaintext

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