Returning Multiple Values From Map Returning Multiple Values From Map ruby ruby

Returning Multiple Values From Map


Use Enumerable#flat_map

b = [0, 3, 6]a = b.flat_map { |x| [x, x+1, x+2] }a # => [0, 1, 2, 3, 4, 5, 6, 7, 8]


Use Enumerable#flat_map

Which is probably not much different than:

p [1, 2, 3].map{|num| [1, 2, 3]}.flatten --output:-[1, 2, 3, 1, 2, 3, 1, 2, 3]