Last active
April 4, 2020 17:39
-
-
Save veronicacannon/f3dcbe4cc4eb149087bdf13812ab0bf1 to your computer and use it in GitHub Desktop.
telldontask exercise1
This file contains 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
# frozen_string_literal: true | |
Map = Struct.new(:addresses) do | |
def within_radius(kms) | |
within_range = [] | |
addresses.each do |address| | |
within_range << address.to_s if address.kms <= kms | |
end | |
within_range | |
end | |
end | |
Address = Struct.new(:street, :number, :distance) do | |
def to_s | |
"#{street} Nr. #{number} (#{distance})" | |
end | |
def kms | |
distance.to_i | |
end | |
end | |
home = Address.new("Home Str.", "1", "10km") | |
work = Address.new("Work Str.", "6", "13km") | |
vacation_home = Address.new("Vacation Str.", "5", "100km") | |
parents_house = Address.new("Parents Str.", "2", "230km") | |
map = Map.new([home, work, vacation_home, parents_house]) | |
puts map.within_radius(50) | |
# Expected: | |
# | |
# => ['Home Str. Nr. 1 (10km)', 'Work Str. Nr. 6 (13km)'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment