Untitled
unknown
plain_text
2 years ago
965 B
5
Indexable
const userTimes = {};
// Process each log entry
logs.forEach(log => {
const [userId, timestamp, action] = log.split(' ');
if (!(userId in userTimes)) {
userTimes[userId] = { signIn: null, signOut: null };
}
// Record sign-in and sign-out times
if (action === 'sign-in') {
userTimes[userId].signIn = parseInt(timestamp, 10);
} else if (action === 'sign-out') {
userTimes[userId].signOut = parseInt(timestamp, 10);
}
});
// Filter user IDs based on maxSpan and sort them
return Object.entries(userTimes)
.filter(([userId, times]) => {
const { signIn, signOut } = times;
// Consider only users who have both sign-in and sign-out times
return signOut !== null && (signOut - signIn) <= maxSpan;
})
.map(([userId]) => userId)
.sort((a, b) => parseInt(a, 10) - parseInt(b, 10));Editor is loading...
Leave a Comment