Zest.

Ruby: map, select and reduce

A short, tested Ruby example for map, select and reduce. Copy it and adjust the names and paths for your project.

Ruby
nums = [1, 2, 3, 4]
nums.map { |n| n * 2 }            # [2, 4, 6, 8]
nums.select(&:even?)             # [2, 4]
nums.reduce(0) { |a, n| a + n }  # 10

Find it in Zest

Search for “ruby map, select and reduce” in Zest and this example appears above the results, with other matches to choose from. Searches stay private.

More Ruby examples

All Ruby examples