Skip to content

Commit abce30a

Browse files
committed
printing entries for a single path
1 parent b77ab50 commit abce30a

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

  • implement-shell-tools/ls

implement-shell-tools/ls/ls.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,14 @@ function getPathEntries(path, aFlag = flags.has("a")) {
3535
return entries;
3636
}
3737

38-
console.log(getPathEntries(paths[0]));
38+
// formatter: if -1 flag, print entry per line
39+
// else all in one line with
40+
function printEntries(entries, onePerLineFlag = flags.has("1")) {
41+
if (onePerLineFlag) {
42+
entries.forEach((e) => console.log(e));
43+
} else {
44+
console.log(entries.join("\t"));
45+
}
46+
}
47+
48+
printEntries(getPathEntries(paths[0]));

0 commit comments

Comments
 (0)