[Defibrillators task] Fix type error - defibrillator instead of defibrilator#1
[Defibrillators task] Fix type error - defibrillator instead of defibrilator#1Slavunderkind wants to merge 2 commits intomasterfrom
Conversation
b8e5d88 to
73f6435
Compare
6a6daec to
bbc0b34
Compare
Training/Easy/defibrillators.rb
Outdated
| def init_defibrilators(defibrilator) | ||
| d_long = parse(defibrilator[4]) | ||
| d_lat = parse(defibrilator[5]) | ||
| def init_defibrillators(defibrillator) |
There was a problem hiding this comment.
If the function is called init_defibrillators, it should take all the objects at once. If you're initializing one, it's better to make the method singular.
Also, add_defibrillator might be a better name, because you're adding it to the existing defibrillators hash
Training/Easy/defibrillators.rb
Outdated
| d_long = parse(defibrilator[4]) | ||
| d_lat = parse(defibrilator[5]) | ||
| def init_defibrillators(defibrillator) | ||
| d_long = parse(defibrillator[4]) |
There was a problem hiding this comment.
parse is too generic of a name.
Training/Easy/defibrillators.rb
Outdated
| end | ||
|
|
||
| def start | ||
| n.times do |
There was a problem hiding this comment.
Here you have the option of either adding inputs one by one, or getting the whole input and parsing it in one go. The latter might be a better option
Training/Easy/defibrillators.rb
Outdated
| init_defibrilators(defib.split(';')) | ||
| init_defibrillators(defib.split(';')) | ||
| end | ||
| puts find_closest(defibrillators) |
There was a problem hiding this comment.
The Ruby object itself should only return the answer. Printing should happen after the fact.
So instead of:
Object.start
You can do
answer = object.start
puts answer
Training/Easy/defibrillators.rb
Outdated
| def find_closest(defibrilators_hash) | ||
| min = defibrilators_hash.values.first | ||
| closest_name = defibrilators_hash.keys.first | ||
| def find_closest(defibrillators_hash) |
There was a problem hiding this comment.
Instead of writing a method yourself, you can use Enumerable#min_by:
closest_name, closest_value = defibrillators_hash.min_by { |pair| pair.last }Also, if you're not going to use the second value, you can write it like this:
closest_name, _ = defibrillators_hash.min_by { |pair| pair.last }| x = calculate_x(d_long, d_lat) | ||
| y = calculate_y(d_lat) | ||
| defibrilators[defibrilator[1]] = distance(x, y) | ||
| defibrillators[defibrillator[1]] = distance(x, y) |
There was a problem hiding this comment.
Inside the distance function, you can use Ruby's "power" operator - so instead of
x * x
you can do
x ** 2
|
|
||
| def start | ||
| n.times do | ||
| Array.new(defibrilators_count) do |
There was a problem hiding this comment.
@evgenispasov-which special for you

No description provided.