Hi I'm stuck with this problem. Hopefully somebody can give me some advice.
I've got a JSON with the last day changes in a application that I work on. I want to get 3 datasets from it. And want to keep de right order in date like the example below:
"log": [{
"objectname": "Lorem Ipsum",
"type": "CREATE",
"timenormal": "Sun Feb 09 2020 22:02:26 GMT+0100",
"closesthours": 22
}, {
"objectname": "This is a Dummy",
"type": "CREATE",
"timenormal": "Sun Feb 09 2020 23:27:46 GMT+0100",
"closesthours": 23
},{
"objectname": "Deleted test",
"type": "DELETE",
"timenormal": "Mon Feb 10 2020 00:30:14 GMT+0100",
"closesthours": 1
},{
"objectname": "Qwerty",
"type": "CREATE",
"timenormal": "Mon Feb 10 2020 00:45:04 GMT+0100",
"closesthours": 1
},{
"objectname": "Deleted test",
"type": "DELETE",
"timenormal": "Mon Feb 10 2020 04:45:14 GMT+0100",
"closesthours": 5
}, {
"objectname": "Hello World",
"type": "CREATE",
"timenormal": "Mon Feb 10 2020 10:51:22 GMT+0100",
"closesthours": 11
}, {
"objectname": "Another one",
"type": "CREATE",
"timenormal": "Mon Feb 10 2020 10:41:22 GMT+0100",
"closesthours": 11
}, {
"objectname": "ABC",
"type": "CREATE",
"timenormal": "Mon Feb 10 2020 21:16:57 GMT+0100",
"closesthours": 21
}, {
"objectname": "test dummy",
"type": "DELETE",
"timenormal": "Mon Feb 10 2020 21:17:00 GMT+0100",
"closesthours": 21
}
]
I know that following is possible to use map for the 'closesthours':
jsondata['log'].map(function(value, index) {return value['closesthours']});
[22, 23, 1, 1, 5, 11, 11, 21, 21]
From there on, I'm stuck. The 3 datasets I want is:
1.) A map with the closesthours combined:
{"hours":"22,23,1,5,11,21"}
2 & 3) Then I realy want to get a count for occurences by closesthours in the dataset for the two types (DELETE and CREATE) For example, I want to get the following back(with the 0 if that type doesn't have te closesthours):
{"type":"CREATE","groupcount":"1,1,1,0,2,1"}
{"type":"DELETE","groupcount":"0,0,1,1,0,1"}
How can I do this in javascript?