Write a Ruby method that, given an array, returns another array that consists of all odd-numbered elements of the first array. For instance, given an array [1, 5, 'yes', 'no', 2.7], it returns [1, 'yes', 2.7].
Write a method that takes an array of strings and a block and calls
this block on each string. Recall that the keyword to call a block is
yield
. The syntax for
the call is the following:
method(["blah", "Blah"]) {...}
Test the method by
passing it a block that prints the result of applying
reverse
to each
string. Print out the original array after the
call.
reverse!
. Print out the original array. Observe the
differences.
Write a method that takes an array and a block and returns a new array
where elements are the results of applying the block to each element
of the original array and returns the resulting array. Test it on an
array of integers and a method
that squares each element. Also test it on an array of a
different type and a different block. Do not use map
for this problem.
Use methods of the class Enumerable to do the following: