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.
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.
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 |
There was a problem hiding this comment.
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 |
|
|
||
| # 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.
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 |
There was a problem hiding this comment.
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!} |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
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! |
There was a problem hiding this comment.
Space missing to the left of {.
Space between { and | missing.
Space missing inside }.
No description provided.