Skip to content

Instantly share code, notes, and snippets.

@ogijun
Created August 28, 2012 01:59
Show Gist options
  • Save ogijun/3494250 to your computer and use it in GitHub Desktop.
Save ogijun/3494250 to your computer and use it in GitHub Desktop.
class Array
def bsearch(e, l = 0, u = length - 1)
if l <= u
m = (l + u)/2
e < self[m] ? u = m - 1 : l = m + 1
e == self[m] ? m : bsearch(e, l, u)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment