summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorKaleb Davis <kalebdavisgithub@gmail.com>2015-10-06 21:06:44 -0400
committerKaleb Davis <kalebdavisgithub@gmail.com>2015-10-06 21:06:44 -0400
commitd73584cc9a7eefbcede32d64fa0fc6177e1640bf (patch)
tree8a4d5b886378f5855f5d86260c8ea73b73f6157a
parent6ac7368b3b8e3ce1ee6c50c9f088553e7cbc6d1a (diff)
Add information about mapping arrays
-rw-r--r--ruby.html.markdown13
1 files changed, 13 insertions, 0 deletions
diff --git a/ruby.html.markdown b/ruby.html.markdown
index 8f23b2e6..cf6bf2ce 100644
--- a/ruby.html.markdown
+++ b/ruby.html.markdown
@@ -269,6 +269,19 @@ end
#=> iteration 4
#=> iteration 5
+# There are a bunch of other helpful looping functions in Ruby,
+# for example "map", "reduce", "inject", the list goes on. Map,
+# for instance, takes the array it's looping over, does something
+# to it as defined in your block, and returns an entirely new array.
+array = [1,2,3,4,5]
+doubled = array.map do |element|
+ element * 2
+end
+puts doubled
+#=> [2,4,6,8,10]
+puts array
+#=> [1,2,3,4,5]
+
grade = 'B'
case grade