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