lodash: count values from array of objects
<p>I have an array of objects like this:</p>

<pre><code>[
{"question":"Q1","answer":"my answer 2"},
{"question":"Q1","answer":"my answer"}
{"question":"Q1","answer":"my answer"}
{"question":"Q2","answer":"answer 2"}
]
</code></pre>

<p>I would like to group by the question keys and return the counts of each answer.</p>

<p>e.g.</p>

<pre><code>{
    "Q1": [{
        "answer": "my answer",
        "count": 2
    }, {
        "answer": "my answer 2",
        "count": 1
    }],
    "Q2": [{
        "answer": "answer 2",
        "count": 1
    }]
}
</code></pre>

<p>,</p>

<p>I am able to <code>groupBy</code> questions using:
<code>.groupBy("question")</code> and count occurances of values using <code>.countBy()</code> but I am not sure how to combine the grouping and counting functions to achieve the desired output?</p>