Skip to content

Commit 9862b65

Browse files
Kyle WeissKyle Weiss
Kyle Weiss
authored and
Kyle Weiss
committed
more cleanup
1 parent 4c0b967 commit 9862b65

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

test_arrays.rb

+7-15
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
veggies.push "Onions"
6060
puts veggies.last, "\n"
6161

62-
some_array = %w[a b c d e f g]
62+
some_array = %w(a b c d e f g) # short syntax for array deifnition - %w()
6363
puts "some_array: #{some_array.join(", ")}"
6464
puts some_array[-3, 2].join(", "), "\n"
6565
# The reason this gives us "e, f", is because: while -3 tells Ruby where to start looking in the array
@@ -83,9 +83,7 @@
8383
# element in the array means they are not found. And so, nil is returned.
8484
# puts a_combi.assoc(2).join(", ")
8585
# puts a_combi.assoc("blue").join(", ")
86-
# puts a_combi.assoc("b").join(", ")
87-
88-
puts
86+
# puts a_combi.assoc("b").join(", "), "\n"
8987

9088
# Here's some interesting stuff - regarding using %w to create an array:
9189
a1 = %w[red green blue]
@@ -99,29 +97,23 @@
9997
puts a_combi.assoc("red").join(", ")
10098
# %w does NOT make [1 2 3] into [1, 2, 3]...
10199
# it DOES, however, make ["1", "2", "3"] - testing it:
102-
puts a_combi.assoc("1").join(", ")
100+
puts a_combi.assoc("1").join(", "), "\n"
103101
# And now it is found - huzzah! No nil.
104102

105-
puts
106-
107103
# Playing around with multiple arrays that start with a given element:
108104
a1 = %w[orange banana cactus]
109105
a2 = %w[leemur hippo kitten]
110106
a3 = %w[orange roflsaurus cheeseburger]
111107
a_combi = [a1, a2, a3]
112108
puts a_combi.join(", ")
113-
puts a_combi.assoc("orange").join(", ")
109+
puts a_combi.assoc("orange").join(", "), "\n"
114110
# The array 'a1' is returned, as it is the first array (found) that starts with the given element (orange).
115111

116-
puts
117-
118-
# Using the previous example (lines 126-133):
112+
# Using the previous example (lines 126-133): testing to ensure we are infact returning a1
119113
puts a_combi.assoc("orange") == a1
120114
# We see that the array is returned, as the above returns true. However...
121-
puts a_combi.assoc("orange").join(", ") == a1
122-
# ...this one returns false - note the usage of .join.
123-
124-
puts
115+
puts a_combi.assoc("orange").join(", ") == a1, "\n"
116+
# ...this one returns false - note the usage of .join. which adds the comma.
125117

126118
# .collect - essentially an each-do for modifying all elements in an array:
127119
a1 = %w[a d ez]

0 commit comments

Comments
 (0)