Skip to content

Instantly share code, notes, and snippets.

@gingeleski
Created January 4, 2015 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gingeleski/7f73586d7273f2b9e96d to your computer and use it in GitHub Desktop.
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.
# 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