Going through an array and applying a code block is a staple of programming, so I’m particularly interested in today’s post on enumerable methods. #each One of the more commonly used methods, this, as you can probably guess, applies a given block through all of the items before returning the Array itself. The return is […]
Author: madisonsites
[] vs .new with Arrays
Going through an array and applying a code block is a staple of programming, so I’m particularly interested in today’s post on enumerable methods. #each One of the more commonly used methods, this, as you can probably guess, applies a given block through all of the items before returning the Array itself. The return is […]
You Pick ’em! Selecting with Arrays
Going through an array and applying a code block is a staple of programming, so I’m particularly interested in today’s post on enumerable methods. #each One of the more commonly used methods, this, as you can probably guess, applies a given block through all of the items before returning the Array itself. The return is […]
Read the frickin’ docs
Going through an array and applying a code block is a staple of programming, so I’m particularly interested in today’s post on enumerable methods. #each One of the more commonly used methods, this, as you can probably guess, applies a given block through all of the items before returning the Array itself. The return is […]
Iterating with Arrays
Going through an array and applying a code block is a staple of programming, so I’m particularly interested in today’s post on enumerable methods. #each One of the more commonly used methods, this, as you can probably guess, applies a given block through all of the items before returning the Array itself. The return is… Continue reading Iterating with Arrays
Murder Mystery Night with Arrays
Welcome to a fun evening of deceit and murder at Hill House. #pop Like a revolver in a dining room, this pops off the last item in the array and shows you the body. victims = [“Yvette”, “Telegram Girl”, “Officer”, “Stranded Motorist”, “Mrs. Ho”, “Mr. Boddy”] victims.pop => “Mr. Boddy” victims => [“Yvette”, “Telegram Girl”, “Officer”,… Continue reading Murder Mystery Night with Arrays
Array Growth
There are a variety of ways to add items to an array. In the beginning… There was #unshift. If you want to add something in the beginning, use it. how_much = [“many”, “slams”, “in”, “an”, “old”, “screen”, “door”] how_much.unshift(“how”) => [“how”, “many”, “slams”, “in”, “an”, “old”, “screen”, “door”] In the end… You can always use… Continue reading Array Growth
[], tell us more about yourself.
Today we’re asking Arrays to talk about everyones favorite subject: themselves. #length || #size An array never gets offended when you ask about its weight. In fact, you can ask in different ways: musnts = [“listen”, “to”, “the”, “musnt’s”, “child”] musnts.length => 5 musnts.size => 5 Of course, if it were empty, those would return 0.… Continue reading [], tell us more about yourself.
Stick ’em up! Get what you want out of Arrays.
Let’s talk about how to access things in Arrays. #[] This can accept a single integer, which represents the index you wish to hit. Arrays are zero based, meaning that the “first” element is not in the “1” spot, but “0”. If the number is negative, it starts from the end of the array. invitation… Continue reading Stick ’em up! Get what you want out of Arrays.
Let’s Make An [Array] Baby
There are a variety of ways to create an array. Literal Constructor Simply set a variable equal to [] arya = [“Stark”, 7, “Thrones”] #=> [“Stark”, 7, “Thrones”] #new Use the #new method on Array. Array.new #=> [] You can give this method a number to give it a size. Array.new(7) #=> [nil, nil,… Continue reading Let’s Make An [Array] Baby