There was an error while loading. Please reload this page.
1 parent d4752a4 commit 30b2b19Copy full SHA for 30b2b19
1 file changed
implement-shell-tools/ls/ls.mjs
@@ -13,19 +13,17 @@ const path = program.args[0] || ".";
13
const options = program.opts();
14
try {
15
const files = await fs.readdir(path);
16
-
17
- for (const file of files) {
18
- if (options.a || !file.startsWith(".")) {
19
- process.stdout.write(file);
20
- if (options.onePerLine) {
21
- process.stdout.write("\n");
22
- } else {
23
- process.stdout.write(" ");
24
- }
25
+ console.log(files)
+ const visibleFiles = files.filter(
+ (file) => options.a || !file.startsWith("."),
+ );
+ if(options.onePerLine)
+ {
+ console.log(visibleFiles.join("\n"))
+ }else{
+ console.log(visibleFiles.join(" "))
26
}
+
27
} catch (error) {
28
console.error(error.message);
29
-}
30
-if(!options.onePerLine)
31
-console.log()
+}
0 commit comments