Skip to content

Commit bcff944

Browse files
committed
fixing
1 parent 90d7793 commit bcff944

File tree

1 file changed

+0
-79
lines changed

1 file changed

+0
-79
lines changed

week2/homework/src/index.js

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,3 @@
11
'use strict';
22

33
// TODO: Write the homework code in this file
4-
const fs = require('fs');
5-
6-
const readHelp = fs.readFileSync('help.txt', 'utf8', (data, err) => {
7-
if (data) {
8-
console.log(data);
9-
}
10-
else if (err) {
11-
throw err;
12-
}
13-
});
14-
const readList = fs.readFileSync('list.txt', 'utf8', (data, err) => {
15-
if (data) {
16-
console.log(data);
17-
}
18-
else if (err) {
19-
throw err;
20-
}
21-
});
22-
// const listArray = [];
23-
// listArray.push(readList);
24-
// listArray.join('\n');
25-
let listArray = readList.split('\n').filter(i => i.length >= 1);
26-
function addList(todos) {
27-
listArray.push(todos);
28-
fs.writeFile('list.txt', listArray.join('\n'), (data, err) => {
29-
if (data) {
30-
console.log('New task added!');
31-
}
32-
else if (err) {
33-
throw err;
34-
}
35-
});
36-
}
37-
38-
function removeList(todos) {
39-
listArray.splice((todos - 1), 1);
40-
fs.writeFile('list.txt', listArray.join('\n'), (data, err) => {
41-
if (data) {
42-
console.log('New task added!');
43-
}
44-
else if (err) {
45-
throw err;
46-
}
47-
});
48-
}
49-
50-
function reset() {
51-
fs.writeFile('list.txt', '', (data, err) => {
52-
if (data) {
53-
console.log('There should be no data here!');
54-
}
55-
else if (err) {
56-
throw err;
57-
}
58-
});
59-
}
60-
61-
const command = process.argv[2];
62-
const task = process.argv[3];
63-
64-
function main() {
65-
if (command === 'help') {
66-
console.log(readHelp);
67-
}
68-
else if (command === 'list') {
69-
console.log(readList);
70-
}
71-
else if (command === 'add') {
72-
// console.log('add', listArray, 'jgkfjg');
73-
addList(task);
74-
}
75-
else if (command === 'remove') {
76-
removeList(task);
77-
}
78-
else if (command === 'reset') {
79-
reset();
80-
}
81-
}
82-
main();

0 commit comments

Comments
 (0)