<!DOCTYPE html>
<html>
<head>
	<title>Arrays and Hashes</title>
	<meta charset="UTF-8">
	<link rel="stylesheet" type="text/css" href="../stylesheets/default.css">
	<link rel="stylesheet" type="text/css" href="../stylesheets/blog.css">
</head>

<body>

		<a href="../blog/wireframe-index.html"><img class="profile" src="../imgs/brian.jpg" alt="Profile Picture" ></a>
    <h1 ><a href="../blog/wireframe-blog-index.html">Brian's Technical Blog</a></h1> 

  	<nav>
        <a href="../blog/wireframe-index.html">Home</a> | <a href="../projects/index.html">Projects</a> | <a href="../blog/wireframe-blog-index.html">Blogs</a> | <a href="https://github.com/brianlmosley">My GitHub</a> | <a href="../blog/about.html">About</a> | <a href="../blog/social-sites.html">Contact</a> 
   	</nav>
		
	

	<table>
		<tr>
			<td>
		
					<p><a href="../blog/wireframe-index.html">Home</a></p>    
					<p><a href="../projects/index.html">Projects</a></p>
					<p><a href="https://github.com/brianlmosley">My GitHub</a></p>
					<p><a href="../blog/git.html"> Git and GitHub Navigation</a></p>
					<p><a href="../blog/css-concepts.html"> The Difference in Space</a></p>
					<p><a href="../blog/arrays-hashes.html"> Arrays and Hashes</a></p>
					<p><a href="../blog/tech-diversity.html"> Diversity in Tech</a></p>
					<p><a href="../blog/enumerable-methods.html"> Ruby: .map</a></p>
					<p><a href="../blog/ruby-classes.html"> Time for Class</a></p>
					<p><a href="../blog/JavaScript.html"> Ruby vs JavaScript</a></p>
					<p><a href="../blog/tech.html"> Ruby Recursion</a></p>
					<p><a href="../blog/wireframe-blog-index.html"> My Blogs</a></p>
					<p><a href="../blog/about.html"> About</a></p>
					<p><a href="../blog/social-sites.html"> Contact</a></p>
			
			</td>
		</tr>
	</table>

	<h4>February 13, 2016</h4>

	<h3><a href="../blog/arrays-hashes.html">Arrays and Hashes:Color Blind</a></h3> 
		<a href="#"><img class="project" src="../imgs/hash-browns.jpg" alt="Project 2 Picture"></a>
		<h6 id="text-comment">Hey Look! Some arrays of Hash Browns! Fresh out the oven for you.</h6>
	<div>
		<p>Arrays and Hashes are two different ways to hold a collection of elements in a data structured container.  In short, arrays are data containers that can store and ordered list of elements while assigning it a corresponding index for its positon within that array. Hashes, on the other hand, are data containers that stores elements as values which must be associated with a callback key in ordered to be retrieved. Again, arrays are a collection of elements while Hashes are a collection of values that are associated with a key- a Key, Value Pair.</p>

		<p>I like to think of Arrays as just a container of elements while Hashes are the next step, a container of elements with their unique identification card. This plays very true in the sense that Hashes must have a unique key for each value that they contain. A Hash can, however, have elements with the same values. </p>

		<p>For example, let’s say you were given the task to go and locate your five best friend’s balls, from a ball rack in elementary school.  Your five best friends are Lisa, Adam, Samantha, Duke, and Lil John. The five balls you take from the school rack have their own color. The colors are red, blue, gold, green, and orange. You then take those balls and present them to your school teach who shakes them inside of a bag before placing each one of those balls into a shoebox. The order of the balls that you place in the shoebox is blue, orange green red, and gold. </p>

		<p>The teacher then asks you, in front of your best friends, “Since, you know your friends so well. Which ball belongs to whom?”</p>


		<p>Visually, this is all you see. An array of balls with colors. </p>

		<pre> shoe_box_array = [“blue”, “orange”, “green”, “red”, “gold"]</pre>

		<p>From this data alone, could you honestly give Lil John his favorite color ball without making a mistake? You have a 1/5 chance and that is if you are lucky. (Or a better chance if you actually paid attention to what his favorite color was when he told you for the fifth time, but then again all the yelling he has done to your right ear has made you partially deaf. I digress).  So in short, the task of you answering correctly is really low. </p>

		<p>Now let’s set up a similar scenario in which you have a remarkable memory, but only with remember things that happen to you concurrently. So this time, your five best friends give you their favorite ball in this order: Lisa – Red, Adam – Blue, Samantha-Gold, Duke-Green, Lil John-Orange. </p>

		<pre>The array looks like this:
shoe_box_array = [“red”, “blue”, “gold”, “green”, “orange”].</pre>

		<p>The array does not look much different from the one above, but instinctively, you know which color ball belongs to which individual. Now a note before we procced, arrays do not have a “normal” counting scheme as other function or things you have encountered in your life. An array index starts at “0”. Which means, when Lisa comes and asks you what color her ball is, for you to give it to her, you would answer with this:</p>

		<pre>shoe_box_array[0]
=>"red"</pre>

		<p>The output would be a red ball! You lucky person you! Now she is happy and you can now use this function as well, to get Lil John to speak to you:</p>

		<pre>shoe_box_array[-1]
=>"organe"</pre>

		<p>The output would be an orange ball. Just like the “1” used to call the first element in the array, the “-1” would be used to call the last element in the array.</p> 

		<p>Now your head hurts as you ask yourself: “What could I have done first, to make this process much easier!” Well I have the answer for you, just use a hash!</p>

			<pre>shoe_box_hash = {
		"Lisa" => "red",
		"Adam" => "blue",
		"Samantha" => "gold",
		"Duke" => "green",
		"Lil John" => "orange"  
		}</pre>

		<p>With this hash, you could have easily accessed any one of your best friends ball because each ball color(value) would be assigned to your friends name (key).  Just take a look at the hash above, if the teacher asked you which color ball belongs to Dude, could you tell me the color? </p>

		<p>Going back to the first example again, let’s say the teacher did ask you which ball belong to Duke; this is how you would answer it:</p>

		<pre>p shoe_box_hash[“Duke”]
=>"green"</pre>

		<p>The output would be “green”.  Just visually speaking, the key in hashes acts like and identification tag that is placed on each value.  For you, it’s like looking at each ball realizing that each ball has your friend’s respective name written on it with a big highlighter.</p> 

		<p>Of course, this is just the tip of the iceberg when it comes to describing both arrays and hashes. Once you get deeper into the inner working of arrays and hashes, you will then realize how powerful each of these containers can be and in which cases you should use them. </p>
	</div>
	
	<div>
		<h6><a href="https://www.instagram.com/_lazy.brian/">Instagram:_lazy.brian</a></h6>
			<a href="https://www.instagram.com/p/-__oi4EwK0/"><img class="insta" src="../imgs/long-walk.PNG" alt="Long Walk" ></a>
			<a href="https://www.instagram.com/p/BAGAL04EwDx/"><img class="insta" src="../imgs/blue-waves.PNG" alt="Blue Waves" ></a>
			<a href="https://www.instagram.com/p/_AIe-okwLI/"><img class="insta" src="../imgs/sun-bridge.PNG" alt="Sun Bridge" ></a>
			<a href="https://www.instagram.com/p/_pl7GoEwGc/"><img class="insta" src="../imgs/insta4.PNG" alt="insta4" ></a>
	</div>

	<footer>
        <a href="../blog/wireframe-index.html">Home</a> | <a href="../projects/index.html">Projects</a> | <a href="../blog/wireframe-blog-index.html">Blogs</a> | <a href="https://github.com/brianlmosley">My GitHubt</a> | <a href="../blog/about.html">About</a> | <a href="../blog/social-sites.html">Contact</a>
	</footer>


</body>
</html>