Created
February 3, 2016 15:48
-
-
Save machineboy2045/435fda81fa756a8074e1 to your computer and use it in GitHub Desktop.
String intersection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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