Created
June 8, 2020 21:00
-
-
Save violetguos/8f078c5460aea7b3086fc13d9e91dae9 to your computer and use it in GitHub Desktop.
TOP's ruby project
This file contains hidden or 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 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