diff options
author | Levi Bostian <levi.bostian@gmail.com> | 2015-10-09 10:02:59 -0500 |
---|---|---|
committer | Levi Bostian <levi.bostian@gmail.com> | 2015-10-09 10:02:59 -0500 |
commit | 4bb350473f861bd1ce0fd2784cf56620cf088382 (patch) | |
tree | 3e4a6ed445e30c22b7e85003a749bee99e7292c4 /ruby.html.markdown | |
parent | 5bbb0200d7f372cd7ada55936e80c131ffb5091a (diff) | |
parent | d73584cc9a7eefbcede32d64fa0fc6177e1640bf (diff) |
Merge pull request #1374 from kalebdavis/patch-2
Add information about mapping arrays
Diffstat (limited to 'ruby.html.markdown')
-rw-r--r-- | ruby.html.markdown | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/ruby.html.markdown b/ruby.html.markdown index 3e85a038..fe142365 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -275,6 +275,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 |