Skip to content

Instantly share code, notes, and snippets.

Created February 25, 2021 06:12
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Ruby substrings exercise
# Return a hash listing each substring present in the dictionary found in the string
def substrings(string, dictionary)
count =
dictionary.each do |word|
count[word] = string.scan(/#{word}/).length if string.scan(/#{word}/).length != 0
puts count
dictionary = ["below", "down", "go", "going", "horn", "how", "howdy", "it", "i",
"low", "own", "part", "partner", "sit"]
substrings("below", dictionary)
substrings("Howdy partner, sit down! How's it going?", dictionary)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment