Find Number Of Same Elements In An Array w/ Blueprints

I think the same problem as here (Find Number Of Same Elements In An TArray - Programming & Scripting - Epic Developer Community Forums) but how can I achieve this using Blueprints only?

Eg. I have a shop which sells the following (which get added to an Array)
Beans, Bread, Eggs, Beans, Beans, Sausages, Bacon, Beans, Sausages, Eggs, Salt, Pepper

Then at the end of the day, I’d like to display the total sold as:
Beans 4, Bread 1, Eggs 2, Sausages 2, Bacon 1, Salt 1, Pepper 1

You could…

Set a integer variable per item that tracks how many sold.
Example: Bought x Beans then Bean = Bean+x so your inventory needs X beans

Or after you have built your array of bought items… make a map of the items and values with a loop:

In the blueprint:
I have a predefined map of items I could buy… all values 0
I clear the map with my O trigger, as this will be a map of after each purchase so a new trigger will be a different purchase.

I take my bought items array and run a for each loop where I find the bought item entry and increment the map value for that key by 1… you can stop and use the map keys/values how ever you want but I also then go and print out a total with a second loop.
( 3 Beans, 2 carrots, ect)

Important for this method: you must have a map variable predefined with all the possible items you can buy. You can build and populate a map dynamically but this method is for a finite amount of items.

Thank you, your Map solution is exactly what I needed. I’d experimented with them, but was unable to figure it out 100% correctly - this is perfect :slight_smile: