Skip to content

Commit 6098359

Browse files
committed
amended my_cat.js to address review on counter variable
1 parent a38f2e9 commit 6098359

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

implement-shell-tools/cat/my_cat.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ if (files.length === 0) {
2424
}
2525

2626
// Global counters across all files
27-
let lineCounter = 1;
28-
let nonBlankCounter = 1;
27+
let counter = 1;
2928

3029
for (const file of files) {
3130
try {
@@ -34,10 +33,10 @@ for (const file of files) {
3433

3534
if (showNoBlankNumb) { // Number only non-blank lines
3635
content = lines.map(line =>
37-
line.trim() === '' ? '' : `${nonBlankCounter++}\t${line}`
36+
line.trim() === '' ? '' : `${counter++}\t${line}`
3837
).join('\n');
3938
} else if (showLineNumb) { // Number all lines
40-
content = lines.map((line) => `${lineCounter++}\t${line}`).join('\n');
39+
content = lines.map((line) => `${counter++}\t${line}`).join('\n');
4140
}
4241
console.log(content);
4342
} catch (err) {

0 commit comments

Comments
 (0)