fork download
  1. module Enumerable
  2. def map_select
  3. reduce([]) { |accumulator, value|
  4. new_value = yield value
  5. accumulator << new_value if new_value
  6. accumulator
  7. }
  8. end
  9. end
  10.  
  11. p (1..10).map_select { |v| v.even? && v * 2 }
Success #stdin #stdout 0.05s 9608KB
stdin
Standard input is empty
stdout
[4, 8, 12, 16, 20]