-
Notifications
You must be signed in to change notification settings - Fork 0
[Horse racing task] Add initialize method and change variable names #4
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
horse_racing.rb
Outdated
| end | ||
|
|
||
| def find_difference | ||
| strenghts = init_strenghts |
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.
strengTH :)
horse_racing.rb
Outdated
| attr_accessor :horses_number | ||
|
|
||
| def initialize | ||
| @horses_number = gets.to_i |
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.
It's better to use count or size instead of number for variables that express count or size
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.
Yes, sure 👍
horse_racing.rb
Outdated
| n.times do | ||
| pi = gets.to_i | ||
| strenghts_array << pi | ||
| horses_number.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.
Try using each_with_object. You can also chain it to .times
b8e5d88 to
73f6435
Compare
383bb52 to
224785d
Compare
Training/Easy/horse_racing.rb
Outdated
| horses_count.times.each_with_object([]) { |_, result| result << gets.to_i }.sort | ||
| end | ||
|
|
||
| def start |
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 the start method altogether, just use your find_difference function:
obj = HorceRacing.new
answer = obj.start
puts answer
or even
answer = HorceRacing.new.start
puts answer
Training/Easy/horse_racing.rb
Outdated
| @horses_count = gets.to_i | ||
| end | ||
|
|
||
| def find_difference |
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.
This method does two things - it inializes strengths and it also finds their difference. Try to refactor it so that it only does one thing
No description provided.