forked from sswebdev/ruby-basics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lists.rb
77 lines (39 loc) · 1.33 KB
/
lists.rb
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
# ARRAYS
# -------------
#
# Change this array to match the people at your table
people = ["Jeff", "Neal", "Mike", "Vince"]
# Example 1: How many names do we have?
number_of_people = people.count
puts number_of_people
# CHALLENGE #1: Can you display the first name in the list?
puts people.first
# CHALLENGE #2: Can you display the last name in the list?
puts people.last
# CHALLENGE #3: Can you display the third name in the list?
puts people[2]
# CHALLENGE #4: Can you display a random name from the list?
puts people.sample
# slot = rand(0..(number_of_people-1))
# puts people[slot]
# CHALLENGE #5: Can you add a new name to the end of the list,
# and then prove that it worked?
people << "Mr. Smith"
puts people.last
# CHALLENGE #6: Can you sort the list into alphabetical order?
puts people.sort
# HASHES
# -------------
# Feel free to modify this data :-)
favorites = { "color" => "Purple", "number" => 3, "fruit" => "cookies" }
# CHALLENGE #6: Can you display your favorite color?
puts favorites["color"]
# CHALLENGE #6: Can you modify the hash to keep track of your favorite song?
favorites["song"] = "Red Rain"
# CHALLENGE #7: Can you add a list of your friends' names?
# For example, thise code:
#
# puts favorites["friends"]
#
# should display the list of the names of your friends.
favorites["friends"] =