Method: Array#bsearch_first
- Defined in:
- lib/array_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.
29 30 31 32 33 34 35 36 |
# File 'lib/array_bsearch.rb', line 29 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 |