My API response includes committers to a git project, but some members are repeated because they share the same name with different email addresses.
Example response:
[
{"id": "122334", "name": "bob", "commits":10, "email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7544351417165b161a">[email protected]</a>"},
{"id": "223411","name": "frank", "commits":4, "email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ec8a9e8d8287ac9b84898899a899ec28f83">[email protected]</a>"},
{"id": "223411","name": "bob", "commits":19, "email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="96f4f9f4d6f7f9fb8f5">[email protected]</a>"},
]
In order to get a result like this:
[
{"name": "bob", "commits":29},
{"name": "frank", "commits":4},
]
I feel like using both a reduce and a loop could work, but maybe there's a simpler approach that others can suggest. It seems like a common issue that should have an everyday solution!
I tried exploring underscore.js' groupBy function, but it seemed too complex for a one-time use and I couldn't get it to work either :)