0

I want to get the Unique categories from my blog posts - but also return the count of how many posts are in each category

Currently I have this

= blog( 'portfolio' ).articles.map { | r | r.data.category }.uniq.sort

I guess I need to remove the Uniq and Sort and do some Group.by then sort.

Any help appreciated to get this one liner sorted and fast

Cheers

Ian

Ian Warner
  • 1,058
  • 13
  • 32

1 Answers1

0

This Stack Overflow question should answer your question too. It shows a number of ways that you could get a Hash mapping from category to count.

Community
  • 1
  • 1
Gerard Condon
  • 761
  • 1
  • 7
  • 22