I'm searching a powerful solution in TypeScript or JavaScript to count occurrences in an array of object. I'd like to do that by Date. (I need it to create some charts)
For example, i have this array :
var arr = [
{date: Wed Jan 20 2016
type: "Apples"},
{date: Mon Feb 29 2016
type: "Peaches"},
{date: Thu Mar 31 2016
type: "Apples"},
{date: Fri Apr 22 2016
type: "Apples"},
{date: Fri Apr 22 2016
type: "Apples"},
{date: Fri Apr 22 2016
type: "Apples"},
{date: Fri Apr 22 2016
type: "Strawberries"}
]
The result I would like to have is the next one :
var arr2 = [
{date: Wed Jan 20 2016
type: ["Apples", 1]},
{date: Mon Feb 29 2016
type: ["Peaches",1]},
{date: Thu Mar 31 2016
type: ["Apples",1]},
{date: Fri Apr 22 2016
type: ["Apples",3],["Strawberries",1]}
]
I don't know why, but I can't find a good solution, I'm working on it during some days...
If anybody knows a trick, a function, or something else?