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