Created
January 4, 2015 07:09
-
-
Save gingeleski/7f73586d7273f2b9e96d to your computer and use it in GitHub Desktop.
Takes a string and dictionary, determines whether any dictionary entries are present as substrings.
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
# Takes string input, dictionary to determines whether any dictionary | |
# entries are present as substrings. | |
def substrings(input,dictionary) | |
input.downcase! | |
result = Hash.new | |
for x in dictionary | |
search = input.scan(x).length | |
result[x] = search unless search < 1 | |
end | |
return result | |
end | |
# EXAMPLE | |
dictionary = ["below","down","go","going"] | |
puts substrings("below",dictionary) | |
# below = 1, low = 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment