Skip to content

Commit 604ccb5

Browse files
committed
implementing first wc statement
1 parent 99dfd5d commit 604ccb5

File tree

1 file changed

+10
-12
lines changed
  • implement-shell-tools/wc

1 file changed

+10
-12
lines changed

implement-shell-tools/wc/wc.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import { promises as fs } from "node:fs";
22
async function wcJsImplement() {
33
let totalLines=0,totalWords=0,TotalBytes=0;
4-
let words;
4+
let words,bytes;
55
const commandLineArray=process.argv.slice(2);
6-
console.log(commandLineArray);
6+
//console.log(commandLineArray);
77
for(const file of commandLineArray){
88
const fileContent=await fs.readFile(file , 'utf-8');
9+
const fileBuffer=await fs.readFile(file);
10+
bytes=fileBuffer.length;
11+
TotalBytes += bytes;
12+
913
const lines=fileContent.split(/\r?\n/);
1014
let linesCount,wordsCount=0;
1115
//Calculate count of lines
@@ -21,16 +25,10 @@ async function wcJsImplement() {
2125
wordsCount += words.length;
2226
}
2327
}
24-
totalWords = +wordsCount;
25-
26-
console.log(file);
27-
console.log(fileContent)
28-
console.log(lines);
29-
console.log(linesCount);
30-
console.log(totalLines);
31-
console.log(words);
32-
console.log(wordsCount);
33-
console.log(totalWords);
28+
totalWords += wordsCount;
29+
console.log(`${linesCount} ${wordsCount} ${bytes} ${file}`);
30+
3431
}
32+
console.log(`${totalLines} ${totalWords} ${TotalBytes} total`);
3533
}
3634
wcJsImplement();

0 commit comments

Comments
 (0)