-
Notifications
You must be signed in to change notification settings - Fork 0
[Defibrillators task] Fix type error - defibrillator instead of defibrilator #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@evgenispasov-which special for you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.

No description provided.