Method: Array#bsearch_first

Defined in:
lib/bsearch.rb

#bsearch_first(range = 0 ... self.length, &block) ⇒ Object Also known as: bsearch

This method searches the FIRST occurrence which satisfies a condition given by a block in binary fashion and return the index of the first occurrence. Return nil if not found.



67
68
69
70
71
72
73
74
# File 'lib/bsearch.rb', line 67

def bsearch_first (range = 0 ... self.length, &block)
  boundary = bsearch_lower_boundary(range, &block)
  if boundary >= self.length || yield(self[boundary]) != 0
    return nil
  else 
    return boundary
  end
end