-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsub_strings.rb
More file actions
26 lines (22 loc) · 832 Bytes
/
sub_strings.rb
File metadata and controls
26 lines (22 loc) · 832 Bytes
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
require 'pry-byebug'
def substrings(str,dictionary)
substring_hash_listing = Hash.new(0)
str.downcase.split.each do |word|
dictionary.each do |substring|
substring_hash_listing[substring] += word.scan(substring).count if word.include?(substring)
end
end
substring_hash_listing
end
dictionary = ["below","down","go","going","horn","how","howdy","it","i","low","own","part","partner","sit"]
puts "Dictionary: #{dictionary}"
test_data = [
"Howdy partner, sit down! How's it going?",
"I will stick to the permissive ASCII-like output while typing into the the STDIN",
"Use chown to own then down the blown sown town!",
"iii howhowhowhow ownownownownown gogogogogogogogogogo"
]
test_data.each do |string|
puts "\nString: #{string}"
puts "Dictinary Listing: #{substrings(string,dictionary)}\n\n"
end