Skip to content

Instantly share code, notes, and snippets.

@longlostnick
Created October 4, 2011 16:44
Show Gist options
  • Save longlostnick/1262136 to your computer and use it in GitHub Desktop.
Save longlostnick/1262136 to your computer and use it in GitHub Desktop.
Ruby Array#bsearch
class Array
def bsearch(e, l = 0, u = length - 1)
return 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment