Intermediate Enumerables • Exercise 4/5

Flat Map

00:00
0
20 points

Instructions

Create a function all_tags that takes an array of posts (hashes)
and returns a flat array of all unique tags.

Each post has a :tags key with an array of strings.

Use flat_map to collect all tags, then uniq to remove duplicates:
```ruby
[[1, 2], [3, 4]].flat_map { |arr| arr }

=> [1, 2, 3, 4]


Example:
```ruby
posts = [
  { title: "Ruby", tags: ["ruby", "programming"] },
  { title: "Rails", tags: ["ruby", "rails"] }
]
all_tags(posts)  # => ["ruby", "programming", "rails"]

Your Code

Results

Click "Run Tests" to see results