How to group counts for ends of a graph

I wrote a function to "normalize deep nested objects like this…