Skip to content

Commit 3de450e

Browse files
committed
Intalled commader library; Create cat.js file
1 parent 407b010 commit 3de450e

14 files changed

Lines changed: 78 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Dependency directory
2+
/node_modules

implement-shell-tools/cat/cat.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { program } from "commander";
2+
import { promises as fs } from "node:fs";
3+
import process from "node:process";
4+
5+
program
6+
.name("count-containing-words")
7+
.description("Counts words in a file that contain a particular character")
8+
.option("-c, --char <char>", "The character to search for", "e")
9+
.argument("<path>", "The file path to process");
10+
11+
program.parse();
12+
13+
const argv = program.args;
14+
if (argv.length != 1) {
15+
console.error(
16+
`Expected exactly 1 argument (a path) to be passed but got ${argv.length}.`
17+
);
18+
process.exit(1);
19+
}
20+
const path = argv[0];
21+
const char = program.opts().char;
22+
23+
const content = await fs.readFile(path, "utf-8");
24+
const countOfWordsContainingChar = content
25+
.split(" ")
26+
.filter((word) => word.includes(char)).length;
27+
console.log(countOfWordsContainingChar);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Implement `ls`
2+
3+
You should already be familiar with the `ls` command line tool.
4+
5+
Your task is to implement your own version of `ls`.
6+
7+
It must act the same as `ls` would, if run from the directory containing this README.md file, for the following command lines:
8+
9+
* `ls -1`
10+
* `ls -1 sample-files`
11+
* `ls -1 -a sample-files`
12+
13+
Matching any additional behaviours or flags are optional stretch goals.
14+
15+
We recommend you start off supporting just `-1`, then adding support for `-a`.

implement-shell-tools/cat/ls/sample-files/.hidden.txt

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Once upon a time...
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
There was a house made of gingerbread.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
It looked delicious.
2+
I was tempted to take a bite of it.
3+
But this seemed like a bad idea...
4+
5+
There's more to come, though...

implement-shell-tools/cat/ls/sample-files/dir/a.txt

Whitespace-only changes.

implement-shell-tools/cat/ls/sample-files/dir/b.txt

Whitespace-only changes.

implement-shell-tools/cat/ls/sample-files/dir/subdir/x.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)