Skip to content

Conversation

samsonovkirill
Copy link
Contributor

@samsonovkirill samsonovkirill commented Apr 3, 2021

No description provided.

sets = towers.map do |tower|
result = []
column = Array.new(@tower_size, " ")
column.each_index do |i|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

each_with_object method might be used in cases you want to fill new Array/Hash by iterating some data,

result[i] = tower[i]
else
result[i] = column[i]
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice practice to use oneliners like result[i] = tower[i] ? tower[i] : column[i]

@@ -0,0 +1,6 @@
require_relative './towers_of_hanoi'

if __FILE__ == $PROGRAM_NAME

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I remember we agreed that this checkup would be excessive

end
@towers = @towers.map{|column| column.reject{|x| x == " "} }
@sets
self.towers = towers.map{|column| column.reject{|x| x == " "} }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of a real project with larger classes and significant amount of variables and methods self.towers = towers might look confusing. In future try to find more clear way of assignment )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants