or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-3/

File Path Filter

Build a utility function that filters arrays of file paths based on glob patterns.

Requirements

Create a function filterPaths(paths, patterns) that:

  1. Takes an array of file path strings (paths) and one or more glob patterns (patterns)
  2. Returns an array containing only the paths that match the provided patterns
  3. Supports multiple patterns - a path should be included if it matches ANY of the patterns
  4. Handles both string and array pattern inputs (single pattern string or array of pattern strings)

The function should support standard glob pattern syntax including:

  • Wildcards (*) for matching within path segments
  • Globstars (**) for matching across directory levels
  • Question marks (?) for single character matching
  • Character classes (e.g., [abc], [0-9])

Test Cases

  • Filtering JavaScript files from a mixed list returns only .js files @test
  • Using multiple patterns matches paths that satisfy any pattern @test
  • Globstar patterns correctly match nested directories @test
  • Empty pattern array returns empty result @test

Implementation

@generates

API

/**
 * Filters an array of file paths based on glob patterns.
 *
 * @param {string[]} paths - Array of file path strings to filter
 * @param {string|string[]} patterns - Glob pattern(s) to match against
 * @returns {string[]} Array of paths that match the pattern(s)
 */
function filterPaths(paths, patterns) {
  // IMPLEMENTATION HERE
}

module.exports = { filterPaths };

Dependencies { .dependencies }

micromatch { .dependency }

Provides glob pattern matching for JavaScript.