Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/core_ext/array.rb
Instance Method Summary collapse
Instance Method Details
#binary_search(value, first = true) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/core_ext/array.rb', line 3 def binary_search(value, first = true) if (self.size > 2) middle_index = self.size/2 middle = self[middle_index] if (middle > value) self[0..middle_index].binary_search(value, first) else self[middle_index..self.size].binary_search(value, first) end else if first self.first else self.last end end end |