Skip to content

London| 2026-MAR-SDC | Imran Mohamed | Sprint 3 | Implement shell tools#450

Open
i786m wants to merge 5 commits into
CodeYourFuture:mainfrom
i786m:implement-shell-tools
Open

London| 2026-MAR-SDC | Imran Mohamed | Sprint 3 | Implement shell tools#450
i786m wants to merge 5 commits into
CodeYourFuture:mainfrom
i786m:implement-shell-tools

Conversation

@i786m
Copy link
Copy Markdown

@i786m i786m commented Mar 31, 2026

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

Implementation of ls, wc and cat command line tools in node.js

@i786m i786m added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 31, 2026
Copy link
Copy Markdown

@SlideGauge SlideGauge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some notes from my side, could you fix them please?

const spacer = ' ';

for (const path of argv) {
const content = await fs.readFile(path, 'utf-8');
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if file is absent?

}
for (const line of lines) {
if (showLineNumbers) {
process.stdout.write(`${spacer} ${lineNumber++} ${line}\n`);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

real cat places tab between numbers and line, and also aligns line number to the length of the number.

for (const line of lines) {
if (showLineNumbers) {
process.stdout.write(`${spacer} ${lineNumber++} ${line}\n`);
} else if (showNonEmptyLineNumbers && line.trim() !== '') {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Real cat -b considers only truly empty lines (zero characters) as blank, not whitespace-only lines.

for (const path of argv) {
const content = await fs.readFile(path, 'utf-8');
const lines = content.split('\n');
while (lines.length > 0 && lines[lines.length - 1] === '') {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while pops all trailing blank lines, not just one. A file intentionally ending with multiple blank lines will have them silently removed.

process.stdout.write(`${line}\n`);
}
}
} No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing newline at end of file.

program
.name('wc')
.description('Counts the number of lines, words, and characters in a file.')
.argument('<path>', 'The path to the file to analyze')
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Real wc accepts multiple files and prints a total row.


const content = await fs.readFile(path, 'utf-8');

const lineCount = content.split('\n').filter(Boolean).length;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File with a blank line in the middle will have it excluded from the count.

const content = await fs.readFile(path, 'utf-8');

const lineCount = content.split('\n').filter(Boolean).length;
const wordCount = content.split(' ').filter(Boolean).length;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only splits on spaces — tabs and newlines between words are not treated as separators.


const lineCount = content.split('\n').filter(Boolean).length;
const wordCount = content.split(' ').filter(Boolean).length;
const characterCount = content.length;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

content.length counts UTF-16 code units. Real wc -c counts bytes.

const lineCount = content.split('\n').filter(Boolean).length;
const wordCount = content.split(' ').filter(Boolean).length;
const characterCount = content.length;
console.log(` ${showLines ? lineCount : ''} ${showWords ? wordCount : ''} ${showCharacters ? characterCount : ''} ${path}`); No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if some flags are missing? Does it affect the format?

@SlideGauge SlideGauge added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants