Ruby Array Selection

Ruby

Write the code that provides the following functionality for the following methods. Ruby already provides the methods for these.

Use Non-Destructive Selection (meaning the original array is left in tact) for the first two methods and Destructive Behavior (original array is affected) for the last two.

The method names should be:

select_arr(arr)
  # select and return all odd numbers from the Array variable `arr`

reject_arr(arr)
  # reject all elements which are divisible by 3

delete_arr(arr)
  # delete all negative elements

keep_arr(arr)
  # keep all non negative elements ( >= 0)
def select_arr(arr) # select and return all odd numbers from the Array variable `arr` end def reject_arr(arr) # reject all elements which are divisible by 3 end def delete_arr(arr) # delete all negative elements end def keep_arr(arr) # keep all non negative elements ( >= 0) end
< >