Skip to content

Commit 30b2b19

Browse files
committed
refactor:
1 parent d4752a4 commit 30b2b19

1 file changed

Lines changed: 11 additions & 13 deletions

File tree

  • implement-shell-tools/ls

implement-shell-tools/ls/ls.mjs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,17 @@ const path = program.args[0] || ".";
1313
const options = program.opts();
1414
try {
1515
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-
}
16+
console.log(files)
17+
const visibleFiles = files.filter(
18+
(file) => options.a || !file.startsWith("."),
19+
);
20+
if(options.onePerLine)
21+
{
22+
console.log(visibleFiles.join("\n"))
23+
}else{
24+
console.log(visibleFiles.join(" "))
2625
}
26+
2727
} catch (error) {
2828
console.error(error.message);
29-
}
30-
if(!options.onePerLine)
31-
console.log()
29+
}

0 commit comments

Comments
 (0)