-
-
Save A6Brgeuka/0741f09ac75691d8827393a472500145 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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