Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/binary_search/pure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ def binary_search(&block)
index = binary_chop(&block)
index ? self[index] : nil
end

def binary_search_index(&block)
binary_chop(&block)
end

private

Expand All @@ -15,7 +19,7 @@ def binary_chop(&block)
lower = 0

while(upper >= lower) do
idx = lower + (upper - lower) / 2
idx = lower + ((upper - lower) / 2)
comp = yield self[idx]

if comp == 0
Expand Down