Skip to content
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

Petra's Ruby refresher #219

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

petrakh
Copy link

@petrakh petrakh commented Aug 19, 2017

No description provided.

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.split("@"))[1].split("."))[0]

Choose a reason for hiding this comment

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

Don't use parentheses around a method call.

lib/questions.rb Outdated
end

# take out all the capital letters from a string
# so 'Hello JohnDoe' becomes 'ello ohnoe'
def remove_capital_letters_from_string(string)
string.gsub!(/[A-Z]/,"")

Choose a reason for hiding this comment

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

Space missing after comma.

lib/questions.rb Outdated
end

# get the average from an array, rounded to the nearest integer
# so [10, 15, 25] should return 17
def average_of_array(array)
(array.reduce(:+)/array.size.to_f).ceil

Choose a reason for hiding this comment

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

Surrounding space missing for operator /.

lib/questions.rb Outdated
end

# add up all the numbers in an array, so [1, 3, 5, 6]
# returns 15
def total_of_array(array)
sum = 0
array.each { |number| sum += number}

Choose a reason for hiding this comment

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

Space missing inside }.

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)
array.select { |word| word == word.reverse}.count

Choose a reason for hiding this comment

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

Space missing inside }.

lib/questions.rb Outdated
end

# sort an array of words by their last letter, e.g.
# ['sky', 'puma', 'maker'] becomes ['puma', 'maker', 'sky']
def array_sort_by_last_letter_of_word(array)
array.sort_by { |word| word[-1]}

Choose a reason for hiding this comment

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

Space missing inside }.

lib/questions.rb Outdated
end

# remove instances of nil AND false from an array
def remove_nils_and_false_from_array(array)
array.reject { |word| word == nil || word == false}

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.
Space missing inside }.

lib/questions.rb Outdated
end

# remove instances of nil (but NOT false) from an array
def remove_nils_from_array(array)
array.reject { |word| word == nil}

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.
Space missing inside }.

lib/questions.rb Outdated
end

# keep only the elements that start with a vowel
def select_elements_starting_with_vowel(array)
array.select { |word| word =~ /^[aeiou]/i}

Choose a reason for hiding this comment

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

Space missing inside }.

lib/questions.rb Outdated
@@ -1,152 +1,194 @@
# keep only the elements that start with an a
def select_elements_starting_with_a(array)
array.select { |word| word[0] == "a"}

Choose a reason for hiding this comment

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

Space missing inside }.

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)
bank_holidays = [Time.new(2014, 12, 26), Time.new(2014, 12, 25), Time.new(2014, 8, 25), Time.new(2014, 5, 26), Time.new(2014, 5, 5), Time.new(2014, 4, 21), Time.new(2014, 4, 18), Time.new(2014, 1, 1)]

Choose a reason for hiding this comment

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

Line is too long. [202/100]

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