I am looking for assistance in creating an asynchronous "getTypes" function that can analyze a list of paths and return an array describing the type of content in each path. The function should handle all cases efficiently and in case of any errors during the operation, it should return "null" for that specific path. I have attempted to write a function myself but encountered issues.
const getTypes = (arr) => {
const prom = arr.reduce((acc, path) => (
acc.then((data) => {
return fs.stat(path).isFile() ? 'file' : 'directory';
})
.catch(() => null)
), Promise.resolve());
return prom;
}
This is how it should operate:
getTypes(['/etc', '/etc/hosts', '/undefined']).then(console.log);
// ['directory', 'file', null]
I am struggling with this implementation, seeking help from someone who can assist. Thank you!