module Ruborithms::Algorithms::BinarySearch::ClassMethods
Public Instance Methods
binary_search(object, value)
click to toggle source
# File lib/ruborithms/algorithms/binary_search.rb, line 11 def binary_search(object, value) min = 0 max = object.count - 1 while max >= min avg = ((max + min) / 2).floor return avg if object[avg] == value if object[avg] > value max = avg - 1 else min = avg + 1 end end end