Skip to content

Conversation

@Slavunderkind
Copy link
Owner

No description provided.

@Slavunderkind Slavunderkind requested review from a user and vasil-gochev January 11, 2017 15:21
@Slavunderkind Slavunderkind changed the title Update solution Update chuck norris task solution Jan 12, 2017
@Slavunderkind Slavunderkind changed the title Update chuck norris task solution [Chuck norris task] Update solution Jan 12, 2017
@Slavunderkind Slavunderkind force-pushed the chuck_norris_solution branch 3 times, most recently from e98757a to 42d02b3 Compare January 13, 2017 10:48
@Slavunderkind Slavunderkind force-pushed the master branch 4 times, most recently from b8e5d88 to 73f6435 Compare January 17, 2017 14:56
end

def start
binary = @message.each_char.each_with_object('') do |char, b|
Copy link
Collaborator

Choose a reason for hiding this comment

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

You don't need to chain each_char with each_with_object - @message has a chars method

end
array = split_series binary.each_char.map(&:to_i)
output = norris_parse array
array = split_series(binary.each_char.map(&:to_i))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here - binary has a chars method

@@ -27,25 +27,24 @@ def split_series(array)
result
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can use each_with_object in the split_series method as well

Also, use meaningful variable names - a and c are not meaningful enough

result += '0' * a[1] + ' '
def norris_parse(series_array)
parsed = series_array.each_with_object('') do |a, result|
result << if a[0].zero?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of adding items with whitespace to a string object and then stripping it, you can add the same items without whitespace to an array object, after which you can use join(' ')

result += '0' * a[1] + ' '
def norris_parse(series_array)
parsed = series_array.each_with_object('') do |a, result|
result << if a[0].zero?
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's better to give meaning to the object's elements if it's not clear what they are - so a[0] and a[1] should have some meaning. You can assign them to local variables and then use them

def norris_parse(series_array)
parsed = series_array.each_with_object('') do |a, result|
result << if a[0].zero?
'00 '
Copy link
Collaborator

Choose a reason for hiding this comment

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

The ternary if/else operator might be used here as well

Copy link
Owner Author

Choose a reason for hiding this comment

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

@vasil-gochev you mean something like this ?
serie[0].zero? ? result << '00' : result << '0'

output = norris_parse array
array = split_series(binary.each_char.map(&:to_i))
output = norris_parse(array)
puts output
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comment as #1 - you can print the answer after getting the answer outside of the class

@@ -27,25 +27,24 @@ def split_series(array)
result
Copy link
Collaborator

Choose a reason for hiding this comment

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

You don't need an attr_accessor for :message if you're not going to set it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants