Skip to content

Commit bab96e4

Browse files
committed
Fix
0 parents  commit bab96e4

File tree

8 files changed

+134
-0
lines changed

8 files changed

+134
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const util = require('util');
2+
const fs = require('fs');
3+
const readfile2 = util.promisify(fs.readFile);
4+
5+
async function main () {
6+
console.log('start')
7+
const file1Pr = readfile2('./test.txt') // Promise
8+
const file2Pr = readfile2('./test2.txt') // Promise
9+
const results = await Promise.all([file1Pr, file2Pr])
10+
console.log(results.map(s => s.toString()))
11+
}
12+
main()
13+

index2.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
function test(num) {
2+
return num * 2;
3+
}
4+
function isOdd(num) {
5+
return num % 2 !== 0 // true # false
6+
}
7+
function sum(a, b) { return a + b }
8+
const arr = [3, 4, 5]
9+
const arr2 = arr.filter(isOdd)
10+
console.log(arr2)
11+
12+
// [a, b, c, d].reduce(+)
13+
// reduce
14+
// a + b + c + d
15+
16+
const tinhTongSoLe = arr => arr
17+
.filter(isOdd)
18+
.reduce(sum)
19+
20+
function expect (value) {
21+
return {
22+
toBe: (toBeValue) => {
23+
if (toBeValue === value) {
24+
console.log('Pass!')
25+
} else {
26+
throw new Error('Error!')
27+
}
28+
}
29+
}
30+
}
31+
32+
// test
33+
function test (msg, func) {
34+
try {
35+
func()
36+
console.log(`${msg} ket thuc kiem thu`)
37+
} catch (err) {
38+
console.error(`${msg} Tra lai ket qua loi`)
39+
}
40+
}
41+
test('tinhTongSoLe', () => {
42+
expect(tinhTongSoLe([1, 2, 4, 3])).toBe(4)
43+
expect(tinhTongSoLe([1, 2, 5])).toBe(6)
44+
expect(tinhTongSoLe([1, 2, 9, 3])).toBe(13)
45+
})
46+

math.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function sum(a, b) {
2+
return a + b;
3+
}
4+
5+
function sumCb(a, b, fn) {
6+
fn(a + b)
7+
}
8+
9+
module.exports = {
10+
sum,
11+
sumCb
12+
}

package-lock.json

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "lesson2",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "node index2.js",
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"keywords": [],
11+
"author": "Truong Dung",
12+
"license": "ISC",
13+
"dependencies": {
14+
"node-emoji": "^1.11.0"
15+
}
16+
}

test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello world

test2.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hoc NodeJSs

0 commit comments

Comments
 (0)