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

6 left to do #227

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

6 left to do #227

wants to merge 1 commit into from

Conversation

congcongbo
Copy link

No description provided.

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[email.index("@")+1...email.index(".")]

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 +.

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.sum.to_f/array.length.to_f)+0.5).to_i

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 /.
Surrounding space missing for operator +.

end

# return the shortest word in an array
def longest_word_in_array(array)
array.max {|a,b| a.length <=> b.length}

Choose a reason for hiding this comment

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

Use max_by(&:length) instead of max { |a, b| a.length <=> b.length }.
Space between { and | missing.
Space missing after comma.
Space missing inside }.

end

# return the shortest word in an array
def shortest_word_in_array(array)
array.min{|a,b| a.length <=> b.length }

Choose a reason for hiding this comment

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

Use min_by(&:length) instead of min { |a, b| a.length <=> b.length }.
Space missing to the left of {.
Space between { and | missing.
Space missing after comma.

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{|x| x.reverse==x}.length

Choose a reason for hiding this comment

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

Space missing to the left of {.
Space between { and | missing.
Surrounding space missing for operator ==.
Space missing inside }.

end

# cut strings in half, and return the first half, e.g.
# '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)
string[0...((string.length.to_f/2).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 /.

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.map{|x| x.reverse}.sort.map{|x| x.reverse}

Choose a reason for hiding this comment

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

Space missing to the left of {.
Space between { and | missing.
Space missing inside }.

end

# remove instances of nil AND false from an array
def remove_nils_and_false_from_array(array)
array.compact!.delete_if{ |x| x==false }

Choose a reason for hiding this comment

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

Space missing to the left of {.
Surrounding space missing for operator ==.

end

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

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

@@ -1,152 +1,181 @@
# keep only the elements that start with an a
def select_elements_starting_with_a(array)
array.select { |x| x[0]=="a" }

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 ==.

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