Class: Array

Inherits:
Object
  • Object
show all
Defined in:
bin/classify_greed

Instance Method Summary collapse

Instance Method Details

#common_lengthObject

return a length of common part of strings.



16
17
18
19
20
21
22
23
24
25
26
27
# File 'bin/classify_greed', line 16

def common_length
  index = 0
  min_length = self.min_by{|item| item.size}.size
  min_length.times do |char_index|
    1.upto(self.size-1) do |str_index|
      char_0 = self[0][char_index]
      char_n = self[str_index][char_index]
      return char_index if char_0 != char_n
    end
  end
  return min_length
end