Guest User

Untitled

a guest
Apr 25th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1. def common_sub(*strings)
  2. reg = Regexp.new strings.shift.split(//).map { |i| "#{i}?" }.join("")
  3. c = nil
  4. strings.each do |s|
  5. return nil unless m = reg.match(s)
  6.  
  7. if c
  8. c = m[0] if c.size > m[0].size
  9. else
  10. c = m[0]
  11. end
  12. end
  13.  
  14. return c
  15. end
  16.  
  17. p common_sub("foobar", "foobaz", "foowhoo")
Add Comment
Please, Sign In to add comment