Created
June 1, 2020 02:44
-
-
Save kleytonmr/756be606251ed660539a9b90f4592d35 to your computer and use it in GitHub Desktop.
Bsearch p2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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