Skip to content

Instantly share code, notes, and snippets.

@violetguos
Created June 8, 2020 21:00
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 violetguos/8f078c5460aea7b3086fc13d9e91dae9 to your computer and use it in GitHub Desktop.
Save violetguos/8f078c5460aea7b3086fc13d9e91dae9 to your computer and use it in GitHub Desktop.
TOP's ruby project
def substrings(words, dictionary)
result = Hash.new(0)
words = words.split(" ")
dictionary.map do |dict|
words.each do |word|
if word.downcase.include?(dict.downcase)
result[dict] += 1
end
end
end
return result
end
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