docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build a utility for analyzing user activity logs to find the last occurrence of specific events or conditions.
You need to implement a function that processes an array of activity log entries and finds the position of the last entry matching specific criteria. This is useful for identifying when a user last performed certain actions or when specific conditions were last met.
Implement a function findLastActivity that:
Each activity object has this structure:
{
id: number,
type: string, // e.g., "login", "logout", "purchase", "view"
userId: number,
role: string, // e.g., "admin", "user", "guest"
timestamp: number
}/**
* Finds the index of the last activity matching the given criterion.
*
* @param {Array} activities - Array of activity objects to search
* @param {Function|Object|string} criterion - The criterion to match activities against
* @returns {number} The index of the last matching activity, or -1 if not found
*/
function findLastActivity(activities, criterion) {
// Implementation here
}
module.exports = { findLastActivity };Provides utility functions for array manipulation and searching.