-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharrays-hashes.html
96 lines (62 loc) · 3.92 KB
/
arrays-hashes.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!-- Arrays and Hashes-->
<!Doctype html>
<html>
<head>
<title>Week Blogs</title>
<link rel="stylesheet" type="text/css" href="stylesheets/default.css">
<link rel="stylesheet" type="text/css" href="stylesheets/blog.css">
</head>
<body>
<!--Logo-->
<img class= "hero-icon"src=http://www.getranked.com.my/wp-content/uploads/2013/01/Sprout_Icon_Clear_BG_Large.png>
<font><a class="title" href=http://mikecerrone.github.io/blog-index.html> Mike's Blog </a></font>
<!--Nav-bar-->
<div class ="nav-bar">
<font> <a class="header" href="http://mikecerrone.github.io/">Home</a></font>
<font><a class="header" href="#">About</a></font>
<font><a class="header" href="#">Contact</a></font>
</div>
<!--nav-bar-end-->
<!--BLOG-POST START-->
<hr>
<h1> Best Friends: Arrays and Hashes </h1>
<h2>A quick guide to differences between Arrays and Hashes </h2>
<h3>September 8th 2015</h3>
<div class="part2">
<p>What happens if we want to work with many pieces of data in ruby? A collection? A series of numbers that we need to put in ascending order? Or a list of names sorted alphabetically? How does Ruby manage that? Ruby gives us two tools: hashes and arrays. Which one should we use? We will dive in to both in this post!</p>
<img src=http://2.bp.blogspot.com/-7ru6qAynuqA/VQpMYwDjf1I/AAAAAAAABdU/BGFkDoZHCS0/s1600/Screen%2BShot%2B2015-03-19%2Bat%2B11.10.11.png>
</div>
<hr>
<div class="part2">
<h3>Array</h3>
<p>The official Ruby documentation definition of arrays, you’ll see that an array is defined as an ordered, integer-indexed collection of objects. What a mouthfull! Lets examine.</p>
<ul>
<li>Ordered: An array starts at a specific point, goes forwards to the end, and then stops. Each one of the items in an array has specific address, and you can always count on each address being one higher than the previous address.</li>
<li>Integer-Indexed: Each item in the array can be accessed by referencing an integer that represents its position in the array.</li>
<li>Collections: An array is a collection, meaning that a single array is actually a reference in memory to a variety of other objects.</li>
<li>Of Any Object: One thing that makes Ruby different from some other languages is that an array can contain any type of legitimate Ruby object.</li>
</ul>
</div>
<hr>
<div class="part2">
<h3>Hash</h3>
<p>A Hash is a collection of key-value pairs like this: "first_name" => "Mike". It is similar to an Array, except that indexing is done via arbitrary keys of any object type, not an integer index.</p>
</div>
<hr>
<div class="part2">
<h4>The Differences Between Arrays and Hashes</h4>
<p>Hashes and Arrays have some key differences:
<ol>
<li>Hash keys are not integer keys. They can be characters, integers, strings, etc. — basically, any Ruby object type. Array indexes are integers only.</li>
<li>The hash keys are not ordered. So, you couldn’t say that a is “first” or that it “comes before”, because Ruby does not look at the order of keys in hashes.</li>
<li>Even though hash keys are not ordered, if you were iterating through a hash Ruby would go through them in the order in which they were added to the hash.</li>
</div>
<hr>
</body>
<div class= "footer-bar">
<font class= "footer" ><a href= https://www.linkedin.com/in/mikecerrone> <img class="icon" src=https://billing.cemc.com/oscp/Portals/0/Linkedin%20icon.png></a> </a></font>
<font class= "footer" ><a href= https://github.com/mikecerrone><img class="icon" src=http://uxrepo.com/static/icon-sets/zocial/svg/github-circled.svg></a> </a></font></a></font>
<font class= "footer" ><a href= https://twitter.com/mikecerrone><img class="icon" src=http://cdn.business2community.com/wp-content/uploads/2015/07/Twitter-icon.png.png></a> </a></font></a></font>
<font class= "footer" ><a href= https://www.facebook.com/mikecerrone><img class="icon" src=https://upload.wikimedia.org/wikipedia/commons/thumb/c/c2/F_icon.svg/2000px-F_icon.svg.png></a> </a></font></a></font>
</div>
</html>