I feel it isn't super explicit that people can only order one drink here, so maybe the function should account for that, eh?
In Ruby
DRINK_COSTS={"Americano"=>2.2,"Latte"=>2.3,"Flat white"=>2.4,"Filter"=>3.50}.freezedefbuy(drinks,cash)costs=drinks.map{|drink|DRINK_COSTS[drink]}response="Sorry, exact change only, try again tomorrow!"response=ifcosts==cash&&drinks.size>1"Here are your beverages, have a nice day!"elsifcosts==cash"Here is your #{drinks.first}, have a nice day!"endend
This would expect drinks to be an array of strings. We could also do something were we could accept either a string or an array with something like drinks = [drinks].flatten where we put the result in an array and then flatten it each time. That way we don't have to worry about the type we get (since we aren't checking for it due to this being Ruby).
I had actually thought about that myself but chose not to consider it at the moment. I might go back and tweak mine to take a collection of drinks as well.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I feel it isn't super explicit that people can only order one drink here, so maybe the function should account for that, eh?
In Ruby
This would expect
drinks
to be an array of strings. We could also do something were we could accept either a string or an array with something like drinks = [drinks].flatten where we put the result in an array and then flatten it each time. That way we don't have to worry about the type we get (since we aren't checking for it due to this being Ruby).I had actually thought about that myself but chose not to consider it at the moment. I might go back and tweak mine to take a collection of drinks as well.