Select Map

Submitted By:
masassiez

Difficulty:
Easy

Tags:
enumerables, procs

Instructions:
The Pattern object not only functions as a Regexp. For example, check out what happens if you do Pattern === element. This problem demonstrates that using a Pattern with #grep will work much like using select and map in combination.

Code:
assert_equal ["1", 2, "3", 4, "5"].grep(/[1-5]/){ |e| e.succ }, ["2", "4", "6"]
assert_equal [0, 1, 3, 5, 6].grep(1..5, &:succ), [2, 4, 6]
assert_equal ["1", "2", "3", "4", "5"].grep(___){ |e| e.succ }, ["2", "4", "6"]
assert_equal [1, 2, 3, 4, 5].grep(___, &:succ), [2, 4, 6]

Your Solution

Ruby 1.9.3

Back to Problems