Intern — Middle
Recursive collection of file paths in a nested structure
livecode
Task condition
The function takes an object describing a file system and returns an array of strings, where each string is a full path to an individual file. The nesting can be arbitrary, but there is only one directory at each level.
/* input data */
const fileTree = [
"a.js",
"b.js",
{
src: [
"some.js",
"other.js",
{
components: ["someComponent.js"],
},
],
},
];
/*
Expected result:
[
'a.js',
'b.js',
'src/some.js',
'src/other.js',
'src/components/someComponent.js'
]
*/
const collectPaths = (arr) => {
};
console.log(collectPaths(fileTree));