i was wondering if someone could help me with returning the count for duplicates?
ive been reading How to count duplicates in Ruby Arrays
and that's very close to what i want. however the code is quite difficult to understand.
for example if i had an array...
[#<Badge id: 1, name: "justice">, #<Badge id: 9, name: "resonator">, #<Badge id: 9, name: "resonator"> ]
i would want a function that would return some indication the user has 2 of the badges 'resonator'.
im trying to create a badge system similar to how stackoverflow's work. some badges can be awarded multiple times, and if they are, i want some form of count on the badges. however ive been having much trouble thinking how to do this. i think first i need to count the amount of duplicates.
ultimately in the end of my code, im just rendering the badges name like so
<li>
<%= badge_item.name %>
</li>
so that it would show something like...
badges:
justice
resonator x2
how can i do this? is removing duplicates the right way to go? help would be appreciated. thank you!