Sha256: 043cf11230f75e79f092658e968b584a69da09b6c7123c3ea0b73ff8c18be74f

Contents?: true

Size: 358 Bytes

Versions: 1

Compression:

Stored size: 358 Bytes

Contents

class Array
  def binary_index(target,lower=0,upper=self.size-1)
    return if lower > upper
    idx = lower + (upper - lower) / 2
    value = self[idx]
    if value == target
      return idx
    elsif value > target
      self.binary_index(target, lower, idx - 1)
    elsif value < target
      self.binary_index(target, idx + 1, upper)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tyler-binary_search-0.1.0 lib/binary_search/pure.rb