Skip to content

Commit b9817fc

Browse files
committed
fix(wc): prevent counting empty lines as words
1 parent 0071dc4 commit b9817fc

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

  • implement-shell-tools/wc

implement-shell-tools/wc/wc.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ try {
3232
try {
3333
for await (const line of file.readLines()) {
3434
count.lines++;
35-
count.words += line.trim().split(/\s+/).length;
35+
const trimmed = line.trim();
36+
if (trimmed.length > 0) {
37+
count.words += trimmed.split(/\s+/).length;
38+
}
3639
}
3740
} finally {
3841
await file.close();

0 commit comments

Comments
 (0)