-
-
Save kaiguogit/0820b6e7b4820faa2919025d7949e813 to your computer and use it in GitHub Desktop.
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
require "pry-byebug" | |
@states = { | |
OR: ['Oregon',['Salem', 'Portland']], | |
FL: ['Florida',['Tallahassee','Jacksonville']], | |
CA: ['California',['Sacramento','Los Angeles']], | |
NY: ['New York',['Albany','New York']], | |
MI: ['Michigan',['Lansing', 'Detroit']], | |
WA: ['Wahsington',['Olympia','Seattle']], | |
IN: ['Indiana',['Boise']] | |
} | |
@taxes = { | |
OR: 7.5, | |
FL: 8.5, | |
CA: 9.5, | |
NY: 10, | |
MI: 7.3, | |
WA: 7.1, | |
IN: 8.2 | |
} | |
def describe_state(state) | |
city = @states[state.to_sym][1].inject("") do |result, a| | |
result + a + " " | |
end | |
"#{state} is for #{@states[state.to_sym][0]}. It has #{@states[state.to_sym][1].length} major #{@states[state.to_sym][1].length > 1 ? "cities" : "city"}: #{city}" | |
end | |
def calculate_tax(state, price) | |
@taxes[state.to_sym] ? tax = @taxes[state.to_sym] : (return "no state found") | |
price += price * (tax) / 100 | |
price.round(2) | |
end | |
def find_state_for_city (city) | |
result = @states.select do |key,value| | |
#binding.pry | |
@states[key][1].include?(city) | |
end | |
result.keys[0] | |
end | |
puts describe_state(:CA) | |
puts describe_state('FL') | |
puts describe_state('OR') | |
puts describe_state('IN') | |
puts calculate_tax('CA',12.99) | |
puts calculate_tax('TEST',12.99) | |
puts find_state_for_city('Seattle') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment