4 ms·
def common_prefix(strs) strs.map(&:chars) .reduce(&:zip) .map(&:flatten) .take_while { |xs| xs.uniq.one? } .map(&:uniq)
by bauerd 9y ago
def common_prefix(strs)
strs.map(&:chars)
.reduce(&:zip)
.map(&:flatten)
.take_while { |xs| xs.uniq.one? }
.map(&:uniq)
.join
end