or run

npx @tessl/cli init
Log in

Version

Files

docs

index.md
tile.json

task.mdevals/scenario-5/

Activity Log Analyzer

Build a utility for analyzing user activity logs to find the last occurrence of specific events or conditions.

Problem Description

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.

Requirements

Implement a function findLastActivity that:

  • Takes an array of activity objects and a search criterion
  • Returns the index of the last activity matching the criterion
  • Returns -1 if no matching activity is found
  • Supports searching by different criteria (activity type, user role, timestamp conditions)

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
}

Test Cases

  • Given an array of activities, finds the index of the last "purchase" activity. @test
  • Given an array of activities, finds the index of the last activity by an "admin" user. @test
  • Returns -1 when no activity matches the search criteria. @test
  • Finds the last activity with a timestamp greater than a specific value. @test

Implementation

@generates

API

/**
 * 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 };

Dependencies { .dependencies }

lodash { .dependency }

Provides utility functions for array manipulation and searching.