If your array has a natural order use binary search.
Use binary search.
Binary search has O(log n)
access time.
Here are the steps on how to use binary search,
bsearch
to find elements or indicesCode example
# assume array is sorted by name!
array.bsearch { |each| "Jamie" <=> each.name } # returns element
(0..array.size).bsearch { |n| "Jamie" <=> array[n].name } # returns index