You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think there is a bug. And the problem seems to appear if the searched value in in the first half of the array (we will always get nil) or in the second half (we will always get 0).
The text was updated successfully, but these errors were encountered:
It works as intended. If you read the docs for the method it mentions that "binary search needs the collection to be sorted in regards to the search criterion". I.e if you have a list sorted ascending you must use a greater than comparison, while if the list is sorted descending you must use a less than comparison.
As described in the comment of [
bsearch_index
](https://github.com/crystal-lang/crystal,which is correct. However, if we test with the following, we get unexpected result.
I think there is a bug. And the problem seems to appear if the searched value in in the first half of the array (we will always get
nil
) or in the second half (we will always get0
).The text was updated successfully, but these errors were encountered: