Skip to content

Commit fafe5fd

Browse files
committed
feat(wc): format results into table with total counts for multiple files
1 parent c6a7649 commit fafe5fd

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

  • implement-shell-tools/wc

implement-shell-tools/wc/wc.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,18 @@ try {
3333

3434
results[filePath] = count;
3535
}
36-
console.log(results);
36+
37+
if (filePaths.length > 1) {
38+
const total = { lines: 0, words: 0, bytes: 0 };
39+
for (const file of Object.values(results)) {
40+
total.lines += file.lines;
41+
total.words += file.words;
42+
total.bytes += file.bytes;
43+
}
44+
results["total"] = total;
45+
}
46+
47+
console.table(results);
3748
} catch (err) {
3849
console.error(err.message);
3950
}

0 commit comments

Comments
 (0)