Skip to content

Instantly share code, notes, and snippets.

@A6Brgeuka
Last active March 23, 2020 21:06
Show Gist options
  • Save A6Brgeuka/0741f09ac75691d8827393a472500145 to your computer and use it in GitHub Desktop.
Save A6Brgeuka/0741f09ac75691d8827393a472500145 to your computer and use it in GitHub Desktop.
console.time()
var users = {
'userId1': {
'01-02-2020': true,
'02-02-2020': true
},
'userId2': {
'02-02-2020': true
},
'userId3': {
'03-02-2020': true
},
'userId4': {
'04-02-2020': true
}
};
var indexes = [...new Array(10).keys()]
var dates = indexes.map(i => moment().subtract(i, 'day').format('DD-MM-YYYY'));
var str = ''
Object.keys(users).map(id => {
var user = users[id];
var userDates = Object.keys(user);
str += `${userDates}|`;
})
var result = dates.reduce((updates, date) => {
updates[date] = str.split(date).length - 1;
return updates;
}, Object.create(null))
console.timeEnd()
console.log(result, 'result')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment