With a slew of technical interviews on the horizon, I figured it would be worth the time to work through a series of basic ruby concepts and coding problems and Basic array manipulation in Ruby
How can you slice this array to create a new array
[:cat,:orange]
Add the element
:apple
on to the end of the array.
Now take
Add the element
Now remove the element
:apple
back off againAdd the element
:fish
to the start of the array.Now remove the element
:fish
.
For this step I'll use the .push , .pop, .unshift and .shift methods. The .push method takes a parameter and adds it to the end of the array. The converse of that is .pop. It removes the last item of the array and returns it. The .unshift and .shift methods work in the very same why, except that they preform the actions on the beginning of the array.
No comments:
Post a Comment