I've got an array of question and different answers (which I build dynamically, so the number of entries and different answers can vary):
var qaArray = [
{ question: "Question", answer: "Answer A"},
{ question: "Question", answer: "Answer B"},
{ question: "Question", answer: "Answer B"},
{ question: "Question", answer: "Answer C"},
{ question: "Question", answer: "Answer A"},
{ question: "Question", answer: "Answer B"},
{ question: "Question", answer: "Answer C"},
{ question: "Question", answer: "Answer A"},
{ question: "Question", answer: "Answer B"},
]
I need a function to build another array object from this, which would hold the 'answer' and 'count', in this case it would be:
[
{ answer: "Answer A", count: 3 },
{ answer: "Answer B", count: 4 },
{ answer: "Answer C", count: 2 },
]
Is there an easy method to do this, without straight forward loops?
lodashhere and usegroupByto perform it easily