-
Notifications
You must be signed in to change notification settings - Fork 395
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
Ruby refresher weekend challenge #208
base: master
Are you sure you want to change the base?
Conversation
bannastre
commented
Jun 24, 2017
- All tests passed
- Fizzbuzz & 99bottles to follow (probably)
- Hello, Ruby, my old friend!
lib/questions.rb
Outdated
end | ||
|
||
# return true if the date is a uk bank holiday for 2014 | ||
# the list of bank holidays is here: | ||
# https://www.gov.uk/bank-holidays | ||
def is_a_2014_bank_holiday?(date) | ||
require 'date' | ||
bank_holidays = [ ["26/12/2014", 'Boxing Day'], |
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.
Space inside square brackets detected.
lib/questions.rb
Outdated
count = 0 | ||
file = File.open(file_path, 'r') | ||
file.each_line do |line| | ||
line.split(' ').each do |word| |
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.
Unused block argument - word. You can omit the argument if you don't care about it.
lib/questions.rb
Outdated
end | ||
|
||
# get the domain name *without* the .com part, from an email address | ||
# so alex@makersacademy.com becomes makersacademy | ||
def get_domain_name_from_email_address(email) | ||
email.match(/(@[a-zA-Z]+)/)[0].gsub('@', '') |
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.
Use delete instead of gsub.
lib/questions.rb
Outdated
end | ||
|
||
# count the numbers of elements in an element which are palindromes | ||
# a palindrome is a word that's the same backwards as forward | ||
# e.g. 'bob'. So in the array ['bob', 'radar', 'eat'], there | ||
# are 2 palindromes (bob and radar), so the method should return 2 | ||
def number_of_elements_that_are_palindromes(array) | ||
count = 0 | ||
array.each.with_index do |word, index| |
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.
Unused block argument - index. If it's necessary, use _ or _index as an argument name to indicate that it won't be used.
lib/questions.rb
Outdated
end | ||
|
||
# turn an array of numbers into two arrays of numbers, one an array of | ||
# even numbers, the other an array of odd numbers | ||
# even numbers come first | ||
# so [1, 2, 3, 4, 5, 6] becomes [[2, 4, 6], [1, 3, 5]] | ||
def separate_array_into_even_and_odd_numbers(array) | ||
result = [] << array.select { |element| element % 2 == 0 } | ||
result << array.select { |element| element % 2 != 0 } |
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.
Use reject instead of inverting select.
lib/questions.rb
Outdated
end | ||
|
||
# turn an array of numbers into two arrays of numbers, one an array of | ||
# even numbers, the other an array of odd numbers | ||
# even numbers come first | ||
# so [1, 2, 3, 4, 5, 6] becomes [[2, 4, 6], [1, 3, 5]] | ||
def separate_array_into_even_and_odd_numbers(array) | ||
result = [] << array.select { |element| element % 2 == 0 } |
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.
Use (element % 2).zero? instead of element % 2 == 0.
lib/questions.rb
Outdated
end | ||
|
||
# turn a positive integer into a negative integer. A negative integer | ||
# stays negative | ||
def make_numbers_negative(number) | ||
number > 0 ? ( -1 * number ) : number |
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.
Use number.positive? instead of number > 0.
Space inside parentheses detected.
lib/questions.rb
Outdated
end | ||
|
||
# remove instances of nil AND false from an array | ||
def remove_nils_and_false_from_array(array) | ||
array.reject { |element| !element } |
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.
Use select instead of inverting reject.
lib/questions.rb
Outdated
end | ||
|
||
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer the use of the nil? predicate.
data/bank_holidays.rb
Outdated
@@ -0,0 +1,9 @@ | |||
@bank_holidays = [ ["26/12/2014", 'Boxing Day'], |
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.
Space inside square brackets detected.