Skip to content

Ruby refresher#216

Open
rogrenke wants to merge 1 commit intomakersacademy:masterfrom
rogrenke:master
Open

Ruby refresher#216
rogrenke wants to merge 1 commit intomakersacademy:masterfrom
rogrenke:master

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

# 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 /.

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


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

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

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

# '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 /.

# ['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 }.

# 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

Development

Successfully merging this pull request may close these issues.

2 participants