Skip to content

Instantly share code, notes, and snippets.

@machineboy2045
Created February 3, 2016 15:48
Show Gist options
  • Save machineboy2045/435fda81fa756a8074e1 to your computer and use it in GitHub Desktop.
Save machineboy2045/435fda81fa756a8074e1 to your computer and use it in GitHub Desktop.
String intersection
def string_intersection(strings, key = 0, intersection = '')
letter = strings.first[key]
return if letter.nil?
if strings.map {|str| str[key] == letter}.all?
return string_intersection(strings, key + 1, intersection + letter)
else
return intersection
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment