or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-10/

File Tree Matcher

Build a utility that recursively searches through a file tree structure and identifies files matching specific patterns across nested directories.

Background

You're building a file organization tool that needs to locate files across deeply nested directory structures. The tool should support flexible pattern matching that can traverse multiple directory levels to find files matching specific criteria.

Requirements

Implement a function findMatchingFiles(fileTree, pattern) that:

  1. Takes a file tree structure (represented as nested objects) where:

    • Keys are file/directory names
    • Values are either null (for files) or nested objects (for directories)
  2. Takes a pattern string that specifies which files to find across any directory depth

  3. Returns an array of matching file paths (using forward slashes as separators)

  4. Handles patterns that need to traverse through multiple directory levels to find matches

File Tree Format

{
  "src": {
    "components": {
      "Button.js": null,
      "Input.js": null
    },
    "utils": {
      "helpers.js": null
    }
  },
  "tests": {
    "unit": {
      "Button.test.js": null
    }
  },
  "README.md": null
}

Pattern Matching Requirements

  • Support finding files at any nesting level that match a given pattern
  • Handle patterns that specify directory traversal to match files in nested subdirectories
  • Return paths in sorted order

Implementation Details

  1. Create a file file-matcher.js that exports the findMatchingFiles function
  2. Create a test file file-matcher.test.js with the test cases below

Test Cases { .test-cases }

Test Case 1: Find all JavaScript files recursively { .test-case @test }

Input:

const fileTree = {
  "src": {
    "index.js": null,
    "lib": {
      "parser.js": null,
      "validator.js": null
    }
  },
  "README.md": null
};

findMatchingFiles(fileTree, "**/*.js");

Expected Output:

["src/index.js", "src/lib/parser.js", "src/lib/validator.js"]

Test Case 2: Find test files in nested directories { .test-case @test }

Input:

const fileTree = {
  "tests": {
    "unit": {
      "math.test.js": null,
      "string.test.js": null
    },
    "integration": {
      "api.test.js": null
    }
  },
  "src": {
    "index.js": null
  }
};

findMatchingFiles(fileTree, "tests/**/*.test.js");

Expected Output:

["tests/integration/api.test.js", "tests/unit/math.test.js", "tests/unit/string.test.js"]

Test Case 3: Find files with specific pattern across all directories { .test-case @test }

Input:

const fileTree = {
  "app": {
    "controllers": {
      "UserController.js": null,
      "AuthController.js": null
    },
    "models": {
      "User.js": null
    }
  },
  "config": {
    "database.js": null
  }
};

findMatchingFiles(fileTree, "**/User*.js");

Expected Output:

["app/controllers/UserController.js", "app/models/User.js"]

Dependencies { .dependencies }

picomatch { .dependency }

Provides glob pattern matching capabilities for flexible file path matching.