-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rb
31 lines (23 loc) · 795 Bytes
/
main.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
dictionary = ["below","down","go","going","horn","how","howdy","it","i","low","own","part","partner","sit"]
def sub_strings(words_array, dictionary)
found_var_array = []
words_array.each do |word|
word = word.downcase
dictionary.each do |word_inside|
if dictionary.include?(word) || word.include?(word_inside)
if word.include?(word_inside)
found_var_array << word_inside
end
end
end
end
the_hash = found_var_array.reduce(Hash.new(0)) do |result, occurrence|
result[occurrence] += 1
result
end
print "the hash#{the_hash}\n\n"
end
print "Enter some text: "
words = gets.chomp
words_array = words.split(" ")
sub_strings(words_array, dictionary)