Mastering Enumerable, Part 1

Flashcard 6 of 7

Is there a single Enumerable method that will accomplish this?

users.map { |user| [user.name, user.age] }.flatten
#=> ["ben", 32, "chad", 50]

Indeed! flat_map to the rescue.

users.flat_map { |user| [user.name, user.age] }
#=> ["ben", 32, "chad", 50]
Return to Flashcard Results