Conversation
4d025a9 to
d2278e1
Compare
e98757a to
42d02b3
Compare
b8e5d88 to
73f6435
Compare
42d02b3 to
58f2017
Compare
Training/Easy/chuck_norris.rb
Outdated
| end | ||
|
|
||
| def start | ||
| binary = @message.each_char.each_with_object('') do |char, b| |
There was a problem hiding this comment.
You don't need to chain each_char with each_with_object - @message has a chars method
Training/Easy/chuck_norris.rb
Outdated
| end | ||
| array = split_series binary.each_char.map(&:to_i) | ||
| output = norris_parse array | ||
| array = split_series(binary.each_char.map(&:to_i)) |
There was a problem hiding this comment.
Same here - binary has a chars method
Training/Easy/chuck_norris.rb
Outdated
| @@ -27,25 +27,24 @@ def split_series(array) | |||
| result | |||
There was a problem hiding this comment.
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? |
There was a problem hiding this comment.
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? |
There was a problem hiding this comment.
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
Training/Easy/chuck_norris.rb
Outdated
| def norris_parse(series_array) | ||
| parsed = series_array.each_with_object('') do |a, result| | ||
| result << if a[0].zero? | ||
| '00 ' |
There was a problem hiding this comment.
The ternary if/else operator might be used here as well
There was a problem hiding this comment.
@vasil-gochev you mean something like this ?
serie[0].zero? ? result << '00' : result << '0'
Training/Easy/chuck_norris.rb
Outdated
| output = norris_parse array | ||
| array = split_series(binary.each_char.map(&:to_i)) | ||
| output = norris_parse(array) | ||
| puts output |
There was a problem hiding this comment.
Same comment as #1 - you can print the answer after getting the answer outside of the class
Training/Easy/chuck_norris.rb
Outdated
| @@ -27,25 +27,24 @@ def split_series(array) | |||
| result | |||
There was a problem hiding this comment.
You don't need an attr_accessor for :message if you're not going to set it
No description provided.