Skip to content

Commit f5c39c9

Browse files
if statement removed for trimming \n at the end and getLineCount function updated
1 parent e8f3c0c commit f5c39c9

1 file changed

Lines changed: 1 addition & 5 deletions

File tree

  • implement-shell-tools/wc

implement-shell-tools/wc/wc.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ for (const path of filePaths) {
3535

3636
fileContent = await fs.readFile(path, "utf-8");
3737

38-
if (fileContent.endsWith("\n")) {
39-
fileContent = fileContent.slice(0, -1);
40-
}
41-
4238
fileData.lineCount = getLineCount(fileContent);
4339
lineCountTotal += fileData.lineCount;
4440

@@ -100,5 +96,5 @@ function getWordCount(text) {
10096
}
10197

10298
function getLineCount(text) {
103-
return text.split("\n").length;
99+
return (text.match(/\n/g) || []).length;
104100
}

0 commit comments

Comments
 (0)