Skip to content

Commit 03aefbe

Browse files
committed
Add 4.2 solution
1 parent 8dc941b commit 03aefbe

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

03-callbacks-and-events/3.1-simple-event.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class FindRegex extends EventEmitter {
1616
find () {
1717
// +++ 3.1 added line
1818
process.nextTick(() => this.emit('start', this.files));
19+
1920
for (const file of this.files) {
2021
readFile(file, 'utf8', (err, content) => {
2122
if (err) {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import fs from "fs";
2+
import path from "path";
3+
4+
const result = {
5+
runningOps: 1,
6+
fileList: [],
7+
};
8+
9+
10+
function listNestedFiles(dirPath, cb) {
11+
fs.readdir(dirPath, {}, (err, files) => {
12+
if (err) {
13+
if (err.code !== "ENOTDIR") return cb(err);
14+
15+
// if it is file -> push to filesList
16+
result.fileList.push(dirPath);
17+
} else {
18+
for (const file of files) {
19+
result.runningOps++;
20+
readDirectory(path.join(dirPath, file), cb);
21+
}
22+
}
23+
24+
result.runningOps--;
25+
26+
process.nextTick(() => {
27+
if (!result.runningOps) return cb(null, result.fileList);
28+
});
29+
});
30+
}

04-callback-patterns/4.3-recursive-find.js

Whitespace-only changes.

05-promises-async-patterns/f

Whitespace-only changes.

0 commit comments

Comments
 (0)