exercism/julia/binary-search/binary-search.jl
2022-08-24 14:28:45 +02:00

15 lines
333 B
Julia

function binarysearch(haystack, needle)
lo, hi = 1, length(haystack)
while lo <= hi
idx = Int(floor((hi + lo ) / 2))
if needle > haystack[idx]
lo = idx + 1
elseif needle < haystack[idx]
hi = idx - 1
else
return idx:idx
end
end
lo:hi
end