- Learn about arrays in Ruby.
Research and then write answers to the following questions in lib/strings.md.
- What is an Array?
- What are some examples of information that would be Arrays as opposed to some other data type?
- What is one way, using Ruby, to retrieve the 6th element in an Array? How about the 8th element? What happens if you try to retrieve the value of the 9999th element (or some element that doesn't exist in the array)?
- The previous question asks about finding, for example, the 6th element in an Array. Is it possible to find the -6th (Notice the negative symbol!) element in an Array? What does that even mean?
- How would you perform an operation on every element inside an Array?
- How do you add elements to an Array?
- Given the Array
["Laura", "Fiona", "Tori"]
, how would you replace"Fiona"
with"Florence"
so that you end up with["Laura", "Florence", "Tori"]
? - What do the methods
push
,pop
,shift
, andunshift
do? - How do you determine how many elements are in an Array?
- How would you reverse the order of elements in an Array?
- How would you convert a String
"Sumeet Jain"
into an Array["Sumeet", "Jain"]
? How about to["S", "u", "m", "e", "e", "t", " ", "J", "a", "i", "n"]
? How would you convert the Array back into a String?
Remember two things:
- You don't need to submit any code to us for this assignment. Just provide in-your-own-words answers for the questions above.
- We're not looking for any kind of advanced writing skills nor any kind of length. Just be clear and thoughtful about what you write--organize it however it makes sense for you.
As always, one resource is Google. Some of the questions above can by entered verbatim into a Google search, and for others that won't be as effective. Either way, expect to read (or watch videos) about more than just the simple answer to each question. Often a question's answer--even one that seems short or simple--doesn't really make sense until after you've read the paragraphs before and after it.
- http://ruby.bastardsbook.com/chapters/collections/ - There is more here than you need, but it's a good reference.