-
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
Answers questions 1-36 #207
base: master
Are you sure you want to change the base?
Conversation
end | ||
|
||
# return true if a string contains any special characters | ||
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverse the order of the operands /\W/ === string.
end | ||
|
||
# get all the elements in an array, up until the first element | ||
# which is greater than five. e.g. | ||
# [1, 3, 5, 4, 1, 2, 6, 2, 1, 3, 7] | ||
# becomes [1, 3, 5, 4, 1, 2] | ||
def get_elements_until_greater_than_five(array) | ||
array.take_while { |element| element <= 5} |
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 missing inside }.
def longest_word_in_array(array) | ||
array.max { |a,b| a.length <=> b.length } |
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 max_by(&:length) instead of max { |a, b| a.length <=> b.length }.
Space missing after comma.
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) | ||
[array.select { |el| el.even? }, array.select { |el| el.odd? } ] |
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.
end | ||
|
||
# turn a positive integer into a negative integer. A negative integer | ||
# stays negative | ||
def make_numbers_negative(number) | ||
-(number.abs) |
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.
Don't use parentheses around a method call.
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) | ||
midpoint = (string.length.to_f / 2).ceil | ||
string[0...(midpoint)] |
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.
Don't use parentheses around a variable.
end | ||
|
||
# discard the first 3 elements of an array, | ||
# e.g. [1, 2, 3, 4, 5, 6] becomes [4, 5, 6] | ||
def all_elements_except_first_3(array) | ||
array.select {|el| array.index(el) > 2 } |
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 between { and | missing.
end | ||
|
||
# don't reverse the array, but reverse every word inside it. e.g. | ||
# ['dog', 'monkey'] becomes ['god', 'yeknom'] | ||
def reverse_every_element_in_array(array) | ||
array.map { |value| value.reverse } |
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.
Unnecessary spacing detected.
@@ -1,152 +1,182 @@ | |||
# keep only the elements that start with an a | |||
def select_elements_starting_with_a(array) | |||
array.select { |word| word[0].downcase == 'a' } |
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 casecmp instead of downcase ==.
Corrects a couple of errors/typos in the questions.