-
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 #216
base: master
Are you sure you want to change the base?
Ruby refresher #216
Conversation
n = remove_nils_and_false_from_array ['a', 'b', nil, nil, false, 'c', nil] | ||
expect(n).to eq ['a', 'b', 'c'] | ||
end | ||
it 'remove_nils_and_false_from_array' do |
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.
Inconsistent indentation detected.
arr = [] | ||
idx = 0 | ||
while idx < array.length do | ||
arr << array[idx] if array[idx]<6 |
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.
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).round |
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.
Surrounding space missing for operator /.
end | ||
|
||
# turn an array into itself repeated twice. So [1, 2, 3] | ||
# becomes [1, 2, 3, 1, 2, 3] | ||
def double_array(array) | ||
[array,array].flatten |
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 after comma.
end | ||
|
||
# return the shortest word in an array | ||
def longest_word_in_array(array) | ||
array.sort_by{|e| e.length}.reverse.first |
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 to the left of {.
Space between { and | missing.
Space missing inside }.
end | ||
|
||
# turn a positive integer into a negative integer. A negative integer | ||
# stays negative | ||
def make_numbers_negative(number) | ||
return number*(-1) if number>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.
Surrounding space missing for operator *.
Don't use parentheses around a literal.
Use number.positive? instead of number>0.
Surrounding space missing for operator >.
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) | ||
i = string.length/2 | ||
i.times{string.chop!} |
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 to the left of {.
Space missing inside {.
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) | ||
i = string.length/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.
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!{|e| e.reverse}.sort! | ||
array.map{|e| e.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.
Space missing to the left of {.
Space between { and | missing.
Space missing inside }.
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!{|e| e.reverse}.sort! |
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 to the left of {.
Space between { and | missing.
Space missing inside }.
No description provided.