map, select, reject
Transform and filter.
Transforming with map
map creates a new array by running the block on each element. The original is unchanged.
nums = [1, 2, 3]
doubled = nums.map { |n| n * 2 }
puts doubled.inspect
puts nums.inspectmap for Strings
map can transform any kind of value, like uppercasing words.
words = ["red", "green"]
puts words.map { |w| w.upcase }.inspectAll lessons in this course
- Creating Ranges
- The Enumerable Module
- map, select, reject
- reduce and each_with_object