Arrays in Ruby are similar to Lists in Python: highly mutable, can contain literally anything, and can do just about anything you might want. Creating them is quite simple, and can be done in many ways, as this code shows:
Which puts this:
Which makes perfect sense.
Manipulating lists is also quite intuitive, and can be accessed in a myriad of ways. Here are examples of most common methods:
which puts a very, very long response (with apologies for egregious repetition so it's legible):
And now it's time for a very special little method: uniq. You saw it earlier, but that's its non-destructive form. When it's made destructive with an !, then it has a very interesting effect:
recall that monster of an array? Well, it's now:
Quite nice, isn't it?
So, now, bubble sort time!
This is the code, and this:
is what it does. With this array:
it produces this result:
And so it goes.
Anyways, that's arrays finished, and a lovely bubble sort to round it all out.
See you on the next post!
No comments:
Post a Comment