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

Ruby refresher #216

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

Ruby refresher #216

wants to merge 1 commit into from

Conversation

rogrenke
Copy link

No description provided.

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

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

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

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

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

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

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!}

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

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}

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!

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

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