Task description: Implement a generate_unique_phone_numbers function. The function shall parse the given text-file.
Content-example:
Trinidad Kemp,(838) 352-2212
Noel Bush,(647) 477-7093
Claudette Davila,(686) 868-8153
Shaun Mcbride,(433) 380-7556
Katy Blanchard,(792) 460-2468
...
Then return a Set with unique phone-numbers. Means: Some phone-numbers might be included multiple times.
My solution:
require "set"
def generate_unique_phone_numbers(path)
numbs = Set.new
if File.exist?(path)
lines = File.readlines(path)
lines.each do |line|
numbs.add line.chomp.split(",").last
end
else
puts "File does not exist."
end
numbs
end
Are there any improvements concerning my solution, which should be implemented?
Would you have done it completely differently? Then how and why?