evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build a utility that recursively searches through a file tree structure and identifies files matching specific patterns across nested directories.
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.
Implement a function findMatchingFiles(fileTree, pattern) that:
Takes a file tree structure (represented as nested objects) where:
null (for files) or nested objects (for directories)Takes a pattern string that specifies which files to find across any directory depth
Returns an array of matching file paths (using forward slashes as separators)
Handles patterns that need to traverse through multiple directory levels to find matches
{
"src": {
"components": {
"Button.js": null,
"Input.js": null
},
"utils": {
"helpers.js": null
}
},
"tests": {
"unit": {
"Button.test.js": null
}
},
"README.md": null
}file-matcher.js that exports the findMatchingFiles functionfile-matcher.test.js with the test cases belowInput:
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"]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"]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"]Provides glob pattern matching capabilities for flexible file path matching.