Skip to content

Instantly share code, notes, and snippets.

@kleytonmr
Created June 1, 2020 02:44
Show Gist options
  • Save kleytonmr/756be606251ed660539a9b90f4592d35 to your computer and use it in GitHub Desktop.
Save kleytonmr/756be606251ed660539a9b90f4592d35 to your computer and use it in GitHub Desktop.
Bsearch p2
arr = [ 1, 1, 2, 3, 5, 8, 13, 21, 34 ]
res = arr.bsearch do |val|
case when val < 19
then +1 when val > 23
then -1
else 0
end
end
res # => 21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment