- Identify the result of method calls on arrays
- Perform simple array manipulations
Now that we've covered the methods .push
, .unshift
, .pop
, and .shift
, we
can take a look at a few more specific methods. Just like the last lab, write
your methods in lib/introduction_to_simple_array_manipulation.rb
using the descriptions below. Run learn
to see the initial test failures, then periodically to see your progress.
Consult the official documentation on Ruby Arrays for the methods you need to use to solve the problems in this lab.
This method takes in two parameters of two different arrays and uses the
.concat
method to add the contents of the second array to the first.
This method takes in two parameters, an Array
and a new element to be added to
the array. it uses the .insert
method to add the new element to the 4th index
of the array.
This method takes in a parameter of an Array
and uses the .uniq
method to
remove any duplicate items.
This method takes in a parameter of an Array
that contains other arrays and
uses the .flatten
method to return an array of strings.
This method takes in two parameters, an Array
and a String
, and uses the
.delete
method to remove any items from the array that are equal to that
string.
This method takes in two parameters, an Array
and an Integer
and uses the
.delete_at
method to delete the element at the index of the array
that is equal to the provided integer.
You have now used the most common methods built into Ruby arrays! Everh Array
can use these methods, giving you the power to modify them in whatever way you
need!