Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
965 B
2
Indexable
Never
   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));
Leave a Comment