I have an array that contains the data of users who joined in the last seven days from the current date. For example:
users=['19 Dec', '21 Dec', '21 Dec']
This array shows that three users joined in the last 7 days. I am attempting to identify the unique occurrences using this function.
`
let occurrences = users.reduce(function (acc, curr) {
return acc[curr] ? ++acc[curr] : (acc[curr] = 1), acc;
}, {});
`
The returned object consists of the following key-value pairs: {19 Dec: 1, 21 Dec: 2}
My goal is to complete the missing values in the object with 0 and their respective dates. Therefore, the final output should be:
{19 Dec: 1, 20 Dec: 0, 21 Dec: 2, 22 Dec: 0, 23 Dec: 0, 24 Dec: 0, 25 Dec: 0}
Could someone please assist me in resolving this issue?
I anticipate filling the missing values in the object with 0 along with their corresponding dates. As a result, the final output should look like this:
{19 Dec: 1, 20 Dec: 0, 21 Dec: 2, 22 Dec: 0, 23 Dec: 0, 24 Dec: 0, 25 Dec: 0}