Conversation
| # count the number of words in a file | ||
| def word_count_a_file(file_path) | ||
| file = File.open(file_path, "r") | ||
| file.each_line do | line | |
There was a problem hiding this comment.
Space before first block parameter detected.
Space after last block parameter detected.
| # where 'special character' means anything apart from the letters | ||
| # a-z (uppercase and lower) or numbers | ||
| def check_a_string_for_special_characters(string) | ||
| /\W/ === string |
There was a problem hiding this comment.
Reverse the order of the operands /\W/ === string.
lib/questions.rb
Outdated
| def titleize_a_string(string) | ||
| articles = ['a', 'and', 'the'] | ||
| string.split.each_with_index.map do |word, index| | ||
| index > 0 && articles.include?(word) ? word : word.capitalize! |
There was a problem hiding this comment.
Use index.positive? instead of index > 0.
lib/questions.rb
Outdated
| # pairing up elements. e.g. ['a', 'b', 'c', 'd'] becomes | ||
| # {'a' => 'b', 'c' => 'd'} | ||
| def convert_array_to_a_hash(array) | ||
| odds_and_evens = array.partition.with_index { |number, index| index.even? } |
There was a problem hiding this comment.
Unused block argument - number. If it's necessary, use _ or _number as an argument name to indicate that it won't be used.
lib/questions.rb
Outdated
| # stays negative | ||
| def make_numbers_negative(number) | ||
| return number if number < 0 | ||
| number - number*2 |
There was a problem hiding this comment.
Surrounding space missing for operator *.
lib/questions.rb
Outdated
| # turn a positive integer into a negative integer. A negative integer | ||
| # stays negative | ||
| def make_numbers_negative(number) | ||
| return number if number < 0 |
There was a problem hiding this comment.
Use number.negative? instead of number < 0.
lib/questions.rb
Outdated
| # round up - so 'apple' becomes 'app' | ||
| def get_first_half_of_string(string) | ||
| return string[0...(string.length/2)] if string.length.even? | ||
| string[0..(string.length/2).round] |
There was a problem hiding this comment.
Surrounding space missing for operator /.
| # 'banana' becomes 'ban'. If the string is an odd number of letters | ||
| # round up - so 'apple' becomes 'app' | ||
| def get_first_half_of_string(string) | ||
| return string[0...(string.length/2)] if string.length.even? |
There was a problem hiding this comment.
Surrounding space missing for operator /.
lib/questions.rb
Outdated
|
|
||
| # remove instances of nil (but NOT false) from an array | ||
| def remove_nils_from_array(array) | ||
| array.select { |element| element != nil } |
There was a problem hiding this comment.
Use reject instead of inverting select.
|
|
||
| # remove instances of nil (but NOT false) from an array | ||
| def remove_nils_from_array(array) | ||
| array.reject { |element| element == nil } |
There was a problem hiding this comment.
Prefer the use of the nil? predicate.
All done except 99 bottles (I'd like to never do that for the third time).