1
2
3
4
5
6
7
8
9
10
11
12
|
const files = ["foo.txt ", ".bar", " ", "baz.foo"];
const filePaths = files.reduce((acc, file) => {
const fileName = file.trim();
if (fileName) {
const filePath = `~/cool_app/${fileName}`;
acc.push(filePath);
}
return acc;
}, []);
// filePaths = [ '~/cool_app/foo.txt', '~/cool_app/.bar', '~/cool_app/baz.foo']
|