Write a function filesInFolder(paths, folder) that returns the names of the files that are right in one folder.
paths is an array of file paths of a project, like the output of git ls-files: folder names and the file name joined with /, for example 'src/utils/math.js'. A path never starts with /. The same path can occur more than once.folder is a string: a folder path from the project root, such as 'src' or 'src/utils'. 'src/' (with a slash at the end) means the same as 'src'. The empty string '' means the project root.folder, not files in its subfolders. 'src2' is a different folder from 'src'.sort(): it compares strings by character codes, so 'README.md' comes before 'app.js'.folder (also when there is no such folder or paths is empty), return an empty array.You can split a path by / to get its parts.
filesInFolder(['src/app.js', 'src/utils/math.js', 'README.md', 'src/index.html', 'src2/x.js'], 'src')Returns [ 'app.js', 'index.html' ]
filesInFolder(['src/app.js', 'src/utils/math.js', 'README.md'], 'src/utils')Returns [ 'math.js' ]
filesInFolder(['src/app.js', 'README.md'], 'docs')Returns []
Asked at ServiceNow · Source
filesInFolder([ 'src/app.js', 'src/utils/math.js', 'README.md', 'src/index.html', 'src2/x.js' ], 'src')[ 'app.js', 'index.html' ]filesInFolder([ 'docs/intro.md', 'tests/login.spec.ts', 'tests/cart.spec.ts' ], 'tests')[ 'cart.spec.ts', 'login.spec.ts' ]filesInFolder([ 'src/app.js', 'README.md' ], 'docs')[]Hidden tests run on Submit.